pub enum Unit {
Point,
Pica,
Inch,
Millimeter,
Centimeter,
Pixel,
Em,
}Expand description
DSSSL Unit (length dimension)
Represents the unit of a quantity. All units can be converted to a canonical representation (inches) for arithmetic operations.
DSSSL Spec §6.2: Quantities are dimensional values
Unit Conversions (from DSSSL spec):
- 1in = 72pt (points)
- 1in = 6pi (picas)
- 1in = 25.4mm (millimeters)
- 1cm = 10mm
- 1pc = 1pi (alternate name)
- 1em = context-dependent (font size)
Variants§
Point
Point (1/72 inch)
Pica
Pica (1/6 inch = 12 points)
Inch
Inch (base unit)
Millimeter
Millimeter (1/25.4 inch)
Centimeter
Centimeter (10mm = 10/25.4 inch)
Pixel
Pixel (1/96 inch - CSS pixel standard)
Em
Em (relative to font size - context-dependent)
Implementations§
Source§impl Unit
impl Unit
Sourcepub fn to_inches(&self, magnitude: f64) -> f64
pub fn to_inches(&self, magnitude: f64) -> f64
Convert this unit to inches (canonical form)
All quantities are normalized to inches for arithmetic operations. Em units default to 12pt unless a font size context is available.
Sourcepub fn from_inches(&self, inches: f64) -> f64
pub fn from_inches(&self, inches: f64) -> f64
Convert from inches to this unit
Sourcepub fn from_suffix(suffix: &str) -> Option<Unit>
pub fn from_suffix(suffix: &str) -> Option<Unit>
Parse unit suffix string
Trait Implementations§
impl Copy for Unit
impl StructuralPartialEq for Unit
Auto Trait Implementations§
impl Freeze for Unit
impl RefUnwindSafe for Unit
impl Send for Unit
impl Sync for Unit
impl Unpin for Unit
impl UnsafeUnpin for Unit
impl UnwindSafe for Unit
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
Mutably borrows from an owned value. Read more