diff options
| author | pml68 <contact@pml68.dev> | 2025-01-13 00:53:05 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-01-13 00:53:41 +0100 |
| commit | e0ccef4781d8c136a71c55db1129a7bccdd4f860 (patch) | |
| tree | a41b2bb48fe1cba56756a7ea50dd3396775f51de /src/lib.rs | |
| parent | refactor: apply clippy suggestions (diff) | |
| download | iced_custom_highlighter-e0ccef4781d8c136a71c55db1129a7bccdd4f860.tar.gz | |
ci: add lint workflow
Diffstat (limited to '')
| -rw-r--r-- | src/lib.rs | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -6,7 +6,6 @@ use iced_widget::core::text::highlighter::{self, Format}; use iced_widget::text_editor::Catalog; use iced_widget::Theme; -use std::collections::HashSet; use std::ops::Range; use std::str::FromStr; use std::sync::LazyLock; @@ -134,10 +133,7 @@ impl<T: Catalog + 'static + Clone + PartialEq> highlighter::Highlighter Some(( range, Highlight { - scope: Scope::from_scopestack( - stack, - custom_scopes.clone(), - ), + scope: Scope::from_scopestack(stack, custom_scopes), style: *style, }, )) @@ -211,6 +207,7 @@ impl<T: Catalog> Highlight<T> { impl Highlight<Theme> { /// The defalt styling function of a [`Highlight`]. + #[must_use] pub fn default_style(theme: &Theme, scope: &Scope) -> Format<Font> { let color = match scope { Scope::Comment | Scope::TagStart => { @@ -362,6 +359,7 @@ impl Scope { } /// Retuns the scope string of the [`Scope`]. + #[must_use] pub fn scope_str(&self) -> &str { match self { Self::Comment => "comment, meta.documentation", @@ -405,15 +403,14 @@ impl Scope { fn from_scopestack( stack: &parsing::ScopeStack, - custom_scopes: Vec<Self>, + custom_scopes: &[Self], ) -> Self { let scopes: Vec<Self> = if custom_scopes.is_empty() { Self::ALL.to_vec() } else { - let mut hashset: HashSet<Self> = - (*Self::ALL).iter().cloned().collect(); - hashset.extend(custom_scopes); - hashset.into_iter().collect() + let mut all = Self::ALL.to_vec(); + all.extend_from_slice(custom_scopes); + all }; let selectors: Vec<(Self, highlighting::ScopeSelectors)> = scopes |
