pub enum Length {
Px(f32),
String(String),
}Expand description
A pure CSS length, no percentage allowed (e.g. font-size, box-shadow).
Variants§
Implementations§
Source§impl Length
impl Length
Sourcepub fn parse(&self) -> ParsedLength
pub fn parse(&self) -> ParsedLength
Parse into a resolved unit. Falls back to Px(0.0) on unparseable
input, for the many existing call sites across the codebase that
expect an infallible result — but unlike the previous behaviour,
this now logs a warning so the fallback is a detectable signal
instead of a silent, indistinguishable zero. Callers that can
surface the failure themselves (e.g. a validator) should prefer
Length::try_parse, which returns None instead of guessing.
Sourcepub fn try_parse(&self) -> Option<ParsedLength>
pub fn try_parse(&self) -> Option<ParsedLength>
Fallible counterpart of Length::parse: None on unparseable
input rather than a silent Px(0.0), and never logs. Prefer this
when the failure can be reported to the caller (e.g. schema
validation) instead of swallowed.
pub fn resolve(&self, ctx: &LengthContext) -> f32
Sourcepub fn px(&self) -> f32
pub fn px(&self) -> f32
Quick px resolution without context (treats em/rem/%/vw/vh as 0). Used
by painters that only need the px value of an explicit length and
have no LengthContext available (see [CssStyle::font_size_px_or]
/ letter_spacing_px / line_height_for in css::style, all built
on this — issue #125 §2).
A relative unit here cannot be resolved correctly no matter what:
em/rem need a font-size base, vw/vh need the real viewport,
% needs a parent box — none of which this context-free accessor
has. Rather than silently returning 0.0 indistinguishably from a
deliberate 0px (the previous behaviour — the “15.6vw renders a
completely black frame with no signal” bug), this now warns loudly
when the dropped value was a relative unit, same fail-loud contract
as [parse_length_or_warn] uses for genuinely unparseable input.
Callers with a real LengthContext should call Length::resolve
instead, which resolves these correctly.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Length
impl<'de> Deserialize<'de> for Length
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Length
impl JsonSchema for Length
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreimpl StructuralPartialEq for Length
Auto Trait Implementations§
impl Freeze for Length
impl RefUnwindSafe for Length
impl Send for Length
impl Sync for Length
impl Unpin for Length
impl UnsafeUnpin for Length
impl UnwindSafe for Length
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more