refactor: address clippy warnings and improve code quality (#409)

- Fix string formatting with modern interpolation syntax
- Improve Debug implementation with finish_non_exhaustive()
- Fix function placement in shape.rs to avoid items_after_statements warning
- Use more idiomatic Rust patterns (map_or_else, next_back)
- Clean up conditional imports in vi.rs
- Convert multiple methods to `const` functions for optimization and consistency
- Introduce `core_maths` for enhanced no-std compatibility
- Update `Cargo.toml` for the new optional dependency and feature adjustments
This commit is contained in:
romanstingler 2025-08-11 21:58:59 +02:00 committed by GitHub
parent e80dbc3607
commit a2f1f4b2a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 282 additions and 299 deletions

View file

@ -30,37 +30,37 @@ impl Color {
/// Get a tuple over all of the attributes, in `(r, g, b, a)` order.
#[inline]
pub fn as_rgba_tuple(self) -> (u8, u8, u8, u8) {
pub const fn as_rgba_tuple(self) -> (u8, u8, u8, u8) {
(self.r(), self.g(), self.b(), self.a())
}
/// Get an array over all of the components, in `[r, g, b, a]` order.
#[inline]
pub fn as_rgba(self) -> [u8; 4] {
pub const fn as_rgba(self) -> [u8; 4] {
[self.r(), self.g(), self.b(), self.a()]
}
/// Get the red component
#[inline]
pub fn r(&self) -> u8 {
pub const fn r(&self) -> u8 {
((self.0 & 0x00_FF_00_00) >> 16) as u8
}
/// Get the green component
#[inline]
pub fn g(&self) -> u8 {
pub const fn g(&self) -> u8 {
((self.0 & 0x00_00_FF_00) >> 8) as u8
}
/// Get the blue component
#[inline]
pub fn b(&self) -> u8 {
pub const fn b(&self) -> u8 {
(self.0 & 0x00_00_00_FF) as u8
}
/// Get the alpha component
#[inline]
pub fn a(&self) -> u8 {
pub const fn a(&self) -> u8 {
((self.0 & 0xFF_00_00_00) >> 24) as u8
}
}
@ -79,23 +79,23 @@ pub enum FamilyOwned {
impl FamilyOwned {
pub fn new(family: Family) -> Self {
match family {
Family::Name(name) => FamilyOwned::Name(SmolStr::from(name)),
Family::Serif => FamilyOwned::Serif,
Family::SansSerif => FamilyOwned::SansSerif,
Family::Cursive => FamilyOwned::Cursive,
Family::Fantasy => FamilyOwned::Fantasy,
Family::Monospace => FamilyOwned::Monospace,
Family::Name(name) => Self::Name(SmolStr::from(name)),
Family::Serif => Self::Serif,
Family::SansSerif => Self::SansSerif,
Family::Cursive => Self::Cursive,
Family::Fantasy => Self::Fantasy,
Family::Monospace => Self::Monospace,
}
}
pub fn as_family(&self) -> Family {
match self {
FamilyOwned::Name(name) => Family::Name(name),
FamilyOwned::Serif => Family::Serif,
FamilyOwned::SansSerif => Family::SansSerif,
FamilyOwned::Cursive => Family::Cursive,
FamilyOwned::Fantasy => Family::Fantasy,
FamilyOwned::Monospace => Family::Monospace,
Self::Name(name) => Family::Name(name),
Self::Serif => Family::Serif,
Self::SansSerif => Family::SansSerif,
Self::Cursive => Family::Cursive,
Self::Fantasy => Family::Fantasy,
Self::Monospace => Family::Monospace,
}
}
}
@ -153,7 +153,7 @@ impl FeatureTag {
/// Stylistic Set 2 (font-specific alternate glyphs)
pub const STYLISTIC_SET_2: Self = Self::new(b"ss02");
pub fn as_bytes(&self) -> &[u8; 4] {
pub const fn as_bytes(&self) -> &[u8; 4] {
&self.0
}
}
@ -170,7 +170,7 @@ pub struct FontFeatures {
}
impl FontFeatures {
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
features: Vec::new(),
}
@ -244,7 +244,7 @@ impl<'a> Attrs<'a> {
/// Create a new set of attributes with sane defaults
///
/// This defaults to a regular Sans-Serif font.
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
color_opt: None,
family: Family::SansSerif,
@ -260,43 +260,43 @@ impl<'a> Attrs<'a> {
}
/// Set [Color]
pub fn color(mut self, color: Color) -> Self {
pub const fn color(mut self, color: Color) -> Self {
self.color_opt = Some(color);
self
}
/// Set [Family]
pub fn family(mut self, family: Family<'a>) -> Self {
pub const fn family(mut self, family: Family<'a>) -> Self {
self.family = family;
self
}
/// Set [Stretch]
pub fn stretch(mut self, stretch: Stretch) -> Self {
pub const fn stretch(mut self, stretch: Stretch) -> Self {
self.stretch = stretch;
self
}
/// Set [Style]
pub fn style(mut self, style: Style) -> Self {
pub const fn style(mut self, style: Style) -> Self {
self.style = style;
self
}
/// Set [Weight]
pub fn weight(mut self, weight: Weight) -> Self {
pub const fn weight(mut self, weight: Weight) -> Self {
self.weight = weight;
self
}
/// Set metadata
pub fn metadata(mut self, metadata: usize) -> Self {
pub const fn metadata(mut self, metadata: usize) -> Self {
self.metadata = metadata;
self
}
/// Set [`CacheKeyFlags`]
pub fn cache_key_flags(mut self, cache_key_flags: CacheKeyFlags) -> Self {
pub const fn cache_key_flags(mut self, cache_key_flags: CacheKeyFlags) -> Self {
self.cache_key_flags = cache_key_flags;
self
}
@ -308,7 +308,7 @@ impl<'a> Attrs<'a> {
}
/// Set letter spacing (tracking) in EM
pub fn letter_spacing(mut self, letter_spacing: f32) -> Self {
pub const fn letter_spacing(mut self, letter_spacing: f32) -> Self {
self.letter_spacing_opt = Some(LetterSpacing(letter_spacing));
self
}
@ -471,7 +471,9 @@ impl AttrsList {
for span in self.spans.iter() {
if span.0.end <= index {
continue;
} else if span.0.start >= index {
}
if span.0.start >= index {
removes.push((span.0.clone(), false));
} else {
removes.push((span.0.clone(), true));