cleanup with clippy

This commit is contained in:
Rowan 2025-07-09 12:01:29 -04:00
parent e69223d3c2
commit 719b33391d
4 changed files with 24 additions and 11 deletions

View file

@ -3,4 +3,6 @@ name = "osstr_traits"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [features]
derive = []

View file

@ -1,5 +1,9 @@
pub mod impls; pub mod impls;
#[cfg(feature = "derive")]
#[macro_use]
extern crate osstr_traits_derive;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::fmt; use std::fmt;
@ -33,11 +37,17 @@ impl OsStringFormatter {
self.inner.push(s); self.inner.push(s);
Ok(()) Ok(())
} }
pub fn into_os_string(self) -> OsString {
self.inner
}
} }
impl ToOsString for OsStringFormatter { impl Default for OsStringFormatter {
fn to_os_string(&self) -> OsString { fn default() -> Self {
self.inner.clone() Self {
inner: OsString::new(),
}
} }
} }
@ -49,7 +59,7 @@ impl<T: OsDisplay> ToOsString for T {
fn to_os_string(&self) -> OsString { fn to_os_string(&self) -> OsString {
let mut formatter = OsStringFormatter::new(); let mut formatter = OsStringFormatter::new();
match self.fmt_os(&mut formatter) { match self.fmt_os(&mut formatter) {
Ok(_) => formatter.to_os_string(), Ok(_) => formatter.into_os_string(),
Err(_) => OsString::new(), Err(_) => OsString::new(),
} }
} }

View file

@ -21,9 +21,10 @@ impl Parse for OsDisplayAttribute {
if lookahead.peek(transparent) { if lookahead.peek(transparent) {
input.parse::<transparent>()?; input.parse::<transparent>()?;
if !input.is_empty() { if !input.is_empty() {
return Err(input.error("Unexpected tokens after `transparent` attribute.")); Err(input.error("Unexpected tokens after `transparent` attribute."))
} else {
Ok(OsDisplayAttribute::Transparent)
} }
return Ok(OsDisplayAttribute::Transparent);
} else if lookahead.peek(LitStr) { } else if lookahead.peek(LitStr) {
let format_string = input.parse()?; let format_string = input.parse()?;

View file

@ -80,7 +80,7 @@ pub fn os_display_derive(input: TokenStream) -> TokenStream {
} }
} }
} else { } else {
let variant_name_str = format!("{}", variant_name); let variant_name_str = format!("{variant_name}");
quote! { f.write_str(#variant_name_str)?; } quote! { f.write_str(#variant_name_str)?; }
}; };
@ -95,7 +95,7 @@ pub fn os_display_derive(input: TokenStream) -> TokenStream {
.unnamed .unnamed
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, _)| Ident::new(&format!("_{}", i), variant.span())) .map(|(i, _)| Ident::new(&format!("_{i}"), variant.span()))
.collect(); .collect();
if let Some(attr) = os_display_attr { if let Some(attr) = os_display_attr {
if let Ok(OsDisplayAttribute::Transparent) = attr.parse_args_with(OsDisplayAttribute::parse) { if let Ok(OsDisplayAttribute::Transparent) = attr.parse_args_with(OsDisplayAttribute::parse) {
@ -214,7 +214,7 @@ pub fn os_display_derive(input: TokenStream) -> TokenStream {
} }
}, },
Fields::Unnamed(fields) => { Fields::Unnamed(fields) => {
let idents: Vec<Ident> = fields.unnamed.iter().enumerate().map(|(i, _)| Ident::new(&format!("_{}", i), name.span())).collect(); let idents: Vec<Ident> = fields.unnamed.iter().enumerate().map(|(i, _)| Ident::new(&format!("_{i}"), name.span())).collect();
quote! { quote! {
let Self(#(#idents),*) = self; let Self(#(#idents),*) = self;
} }
@ -274,7 +274,7 @@ fn parse_os_display_format_string(
let mut placeholder_content = String::new(); let mut placeholder_content = String::new();
while let Some(p) = chars.next() { for p in &mut chars {
if p == '}' { if p == '}' {
break; break;
} }