From 37757cfd57e4a960d368773a7df4bea01d815eae Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Mon, 13 Oct 2025 18:51:32 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[unit]=20A=C3=B1ade=20m=C3=A9todo?= =?UTF-8?q?=20`is=5Fnumeric`=20en=20`UnitValue`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/html/unit.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/html/unit.rs b/src/html/unit.rs index b6a9bc7..b67e8b1 100644 --- a/src/html/unit.rs +++ b/src/html/unit.rs @@ -106,6 +106,31 @@ pub enum UnitValue { RelVw(f32), } +impl UnitValue { + /// Indica si el valor es **numérico**. + /// + /// Devuelve `true` para `Zero` y las unidades absolutas/relativas, y `false` para + /// [`UnitValue::None`] y [`UnitValue::Auto`]. + /// + /// # Ejemplos + /// + /// ```rust + /// # use pagetop::prelude::*; + /// // Numéricos (incluido el cero sin unidad). + /// assert!(UnitValue::Zero.is_numeric()); + /// assert!(UnitValue::Px(0).is_numeric()); + /// assert!(UnitValue::Px(10).is_numeric()); + /// assert!(UnitValue::RelPct(33.0).is_numeric()); + /// // No numéricos. + /// assert!(!UnitValue::None.is_numeric()); + /// assert!(!UnitValue::Auto.is_numeric()); + /// ``` + #[inline] + pub const fn is_numeric(&self) -> bool { + !matches!(self, UnitValue::None | UnitValue::Auto) + } +} + /// Formatea la unidad como cadena CSS. /// /// Reglas: