From f72c81a7571888251e23999dcdc3daf7d567d7bf Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 31 Jan 2023 19:29:01 +0100 Subject: [PATCH] More `PartialEq` impls for `EcoString` --- src/export/pdf/page.rs | 4 +--- src/ide/complete.rs | 2 +- src/model/content.rs | 2 +- src/syntax/ast.rs | 2 +- src/util/eco.rs | 12 ++++++++++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index d1a2e70e5..ef6c0ccc0 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -115,9 +115,7 @@ fn write_page(ctx: &mut PdfContext, page: Page) { link.subtype(AnnotationType::Link).rect(rect); match dest { Destination::Url(uri) => { - link.action() - .action_type(ActionType::Uri) - .uri(Str(uri.as_str().as_bytes())); + link.action().action_type(ActionType::Uri).uri(Str(uri.as_bytes())); } Destination::Internal(loc) => { let index = loc.page.get() - 1; diff --git a/src/ide/complete.rs b/src/ide/complete.rs index 5c64d8016..eda1410fc 100644 --- a/src/ide/complete.rs +++ b/src/ide/complete.rs @@ -407,7 +407,7 @@ fn import_completions( } for (name, value) in module.scope().iter() { - if existing.iter().all(|ident| ident.as_str() != name.as_str()) { + if existing.iter().all(|ident| ident.as_str() != name) { ctx.value_completion(Some(name.clone()), value, None); } } diff --git a/src/model/content.rs b/src/model/content.rs index 143f97aab..e6cb6d287 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -173,7 +173,7 @@ impl Content { for modifier in &self.modifiers { if let Modifier::Field(other, value) = modifier { - if name == other.as_str() { + if name == other { return Some(value.clone()); } } diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index e844f6222..af7fedce9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -459,7 +459,7 @@ impl Shorthand { /// Get the shorthanded character. pub fn get(&self) -> char { - let text = self.0.text().as_str(); + let text = self.0.text(); Self::LIST .iter() .find(|&&(s, _)| s == text) diff --git a/src/util/eco.rs b/src/util/eco.rs index dccb68a82..ceaac2f57 100644 --- a/src/util/eco.rs +++ b/src/util/eco.rs @@ -262,6 +262,18 @@ impl PartialEq<&str> for EcoString { } } +impl PartialEq for str { + fn eq(&self, other: &EcoString) -> bool { + self.eq(other.as_str()) + } +} + +impl PartialEq for &str { + fn eq(&self, other: &EcoString) -> bool { + (*self).eq(other.as_str()) + } +} + impl Ord for EcoString { fn cmp(&self, other: &Self) -> Ordering { self.as_str().cmp(other.as_str())