From 609fbcf4c14d7107430a3d627cf4e3cb636d91d6 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Tekuri Date: Fri, 24 May 2024 00:39:33 +0530 Subject: [PATCH] clippy: fix warnings --- src/draft.rs | 2 +- src/validator.rs | 28 ++++++++++------------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/draft.rs b/src/draft.rs index ffcd7a1..783f18d 100644 --- a/src/draft.rs +++ b/src/draft.rs @@ -395,7 +395,7 @@ impl Draft { if let Some(i) = ptr.find('/') { (&ptr[..i], &ptr[i..]) } else { - (&ptr, "") + (ptr, "") } } diff --git a/src/validator.rs b/src/validator.rs index 5dae560..be5f78b 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -1020,21 +1020,6 @@ pub enum InstanceToken<'v> { Item(usize), } -impl<'v> InstanceToken<'v> { - fn to_string(tokens: &[InstanceToken]) -> String { - use InstanceToken::*; - let mut r = String::new(); - for tok in tokens { - r.push('/'); - match tok { - Prop(s) => r.push_str(&escape(s)), - Item(i) => write!(&mut r, "{i}").expect("write to String should never fail"), - } - } - r - } -} - impl<'v> From for InstanceToken<'v> { fn from(prop: String) -> Self { InstanceToken::Prop(prop.into()) @@ -1077,9 +1062,16 @@ impl<'v> InstanceLocation<'v> { } } -impl<'v> ToString for InstanceLocation<'v> { - fn to_string(&self) -> String { - InstanceToken::to_string(&self.tokens) +impl<'v> Display for InstanceLocation<'v> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for tok in &self.tokens { + f.write_char('/')?; + match tok { + InstanceToken::Prop(s) => f.write_str(&escape(s))?, + InstanceToken::Item(i) => write!(f, "{i}")?, + } + } + Ok(()) } }