Skip to content

Commit d2519c0

Browse files
authored
Add AttrValue::as_int() (#229)
We had a `AttrValue::as_uint()` method to retrieve a `AttrValue::UInt`, this adds a similar `AttrValue::as_int()` for `AttrValue::Int`. Signed-off-by: Oriol Brufau <[email protected]>
1 parent 092e34b commit d2519c0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

style/attr.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,22 @@ impl AttrValue {
335335
}
336336
}
337337

338-
/// Return the AttrValue as its integer representation, if any.
338+
/// Return the AttrValue as its signed integer representation, if any.
339+
/// This corresponds to attribute values returned as `AttrValue::Int(_)`
340+
/// by `VirtualMethods::parse_plain_attribute()`.
341+
///
342+
/// ## Panics
343+
///
344+
/// Panics if the `AttrValue` is not a `Int`
345+
pub fn as_int(&self) -> i32 {
346+
if let AttrValue::Int(_, value) = *self {
347+
value
348+
} else {
349+
panic!("Int not found");
350+
}
351+
}
352+
353+
/// Return the AttrValue as its unsigned integer representation, if any.
339354
/// This corresponds to attribute values returned as `AttrValue::UInt(_)`
340355
/// by `VirtualMethods::parse_plain_attribute()`.
341356
///
@@ -350,7 +365,7 @@ impl AttrValue {
350365
}
351366
}
352367

353-
/// Return the AttrValue as a dimension computed from its integer
368+
/// Return the AttrValue as a dimension computed from its unsigned integer
354369
/// representation, assuming that integer representation specifies pixels.
355370
///
356371
/// This corresponds to attribute values returned as `AttrValue::UInt(_)`

0 commit comments

Comments
 (0)