cleanup with clippy
This commit is contained in:
parent
e69223d3c2
commit
719b33391d
4 changed files with 24 additions and 11 deletions
|
@ -3,4 +3,6 @@ name = "osstr_traits"
|
|||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
[features]
|
||||
derive = []
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
pub mod impls;
|
||||
|
||||
#[cfg(feature = "derive")]
|
||||
#[macro_use]
|
||||
extern crate osstr_traits_derive;
|
||||
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fmt;
|
||||
|
||||
|
@ -33,11 +37,17 @@ impl OsStringFormatter {
|
|||
self.inner.push(s);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn into_os_string(self) -> OsString {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl ToOsString for OsStringFormatter {
|
||||
fn to_os_string(&self) -> OsString {
|
||||
self.inner.clone()
|
||||
impl Default for OsStringFormatter {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
inner: OsString::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +59,7 @@ impl<T: OsDisplay> ToOsString for T {
|
|||
fn to_os_string(&self) -> OsString {
|
||||
let mut formatter = OsStringFormatter::new();
|
||||
match self.fmt_os(&mut formatter) {
|
||||
Ok(_) => formatter.to_os_string(),
|
||||
Ok(_) => formatter.into_os_string(),
|
||||
Err(_) => OsString::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ impl Parse for OsDisplayAttribute {
|
|||
if lookahead.peek(transparent) {
|
||||
input.parse::<transparent>()?;
|
||||
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) {
|
||||
let format_string = input.parse()?;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ pub fn os_display_derive(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
let variant_name_str = format!("{}", variant_name);
|
||||
let variant_name_str = format!("{variant_name}");
|
||||
quote! { f.write_str(#variant_name_str)?; }
|
||||
};
|
||||
|
||||
|
@ -95,7 +95,7 @@ pub fn os_display_derive(input: TokenStream) -> TokenStream {
|
|||
.unnamed
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, _)| Ident::new(&format!("_{}", i), variant.span()))
|
||||
.map(|(i, _)| Ident::new(&format!("_{i}"), variant.span()))
|
||||
.collect();
|
||||
if let Some(attr) = os_display_attr {
|
||||
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) => {
|
||||
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! {
|
||||
let Self(#(#idents),*) = self;
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ fn parse_os_display_format_string(
|
|||
|
||||
let mut placeholder_content = String::new();
|
||||
|
||||
while let Some(p) = chars.next() {
|
||||
for p in &mut chars {
|
||||
if p == '}' {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue