pub struct HwpUnit(/* private fields */);Expand description
The universal measurement unit used throughout HWP documents.
Internally an i32 where 1 point = 100 HwpUnit.
repr(transparent) guarantees zero overhead over a bare i32.
FROZEN: Do not change the internal representation after v1.0.
§Valid Range
[-100_000_000, 100_000_000] – comfortably covers A0 paper
(841 mm width ~ 2_384_252 HwpUnit).
§Examples
use hwpforge_foundation::HwpUnit;
let one_inch = HwpUnit::from_inch(1.0).unwrap();
assert_eq!(one_inch.as_i32(), 7200);Implementations§
Source§impl HwpUnit
impl HwpUnit
Sourcepub fn new(value: i32) -> FoundationResult<Self>
pub fn new(value: i32) -> FoundationResult<Self>
Creates an HwpUnit from a raw i32, validating the range.
§Errors
Returns FoundationError::InvalidHwpUnit when value lies
outside [MIN_VALUE, MAX_VALUE].
§Examples
use hwpforge_foundation::HwpUnit;
assert!(HwpUnit::new(0).is_ok());
assert!(HwpUnit::new(200_000_000).is_err());Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Returns true if this unit is zero.
Useful as a skip_serializing_if predicate for serde.
Sourcepub fn from_pt(pt: f64) -> FoundationResult<Self>
pub fn from_pt(pt: f64) -> FoundationResult<Self>
Sourcepub fn from_mm(mm: f64) -> FoundationResult<Self>
pub fn from_mm(mm: f64) -> FoundationResult<Self>
Constructs an HwpUnit from millimeters.
§Errors
Returns an error when mm is non-finite or the converted
value exceeds the valid range.
Sourcepub fn from_inch(inch: f64) -> FoundationResult<Self>
pub fn from_inch(inch: f64) -> FoundationResult<Self>
Constructs an HwpUnit from inches.
§Errors
Returns an error when inch is non-finite or the converted
value exceeds the valid range.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HwpUnit
impl<'de> Deserialize<'de> for HwpUnit
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl JsonSchema for HwpUnit
impl JsonSchema for HwpUnit
Source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for HwpUnit
impl Ord for HwpUnit
Source§impl PartialOrd for HwpUnit
impl PartialOrd for HwpUnit
impl Copy for HwpUnit
impl Eq for HwpUnit
impl StructuralPartialEq for HwpUnit
Auto Trait Implementations§
impl Freeze for HwpUnit
impl RefUnwindSafe for HwpUnit
impl Send for HwpUnit
impl Sync for HwpUnit
impl Unpin for HwpUnit
impl UnwindSafe for HwpUnit
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.