pub enum AttributeValue {
Null,
String(String),
BytesHex(Vec<u8>),
BytesBase64(Vec<u8>),
Int(i32),
IntHex(u32),
Long(i64),
LongHex(u64),
Float(f32),
Double(f64),
Boolean(bool),
}Expand description
A typed attribute value.
Each variant is one of the value types of the wire format. Use
as_str to render any variant as text, or a typed accessor
such as as_int to read a specific one.
§Examples
use android_abx::AttributeValue;
let value = AttributeValue::Int(42);
assert_eq!(value.as_int(), Some(42));
assert_eq!(value.as_bool(), None);
assert_eq!(value.as_str(), "42");Variants§
Null
No value.
String(String)
A string.
BytesHex(Vec<u8>)
Bytes, rendered as lowercase hex.
BytesBase64(Vec<u8>)
Bytes, rendered as Base64.
Int(i32)
A 32-bit integer, rendered in decimal.
IntHex(u32)
A 32-bit integer, rendered in signed hex.
Long(i64)
A 64-bit integer, rendered in decimal.
LongHex(u64)
A 64-bit integer, rendered in signed hex.
Float(f32)
A 32-bit float.
Double(f64)
A 64-bit float.
Boolean(bool)
A boolean.
Implementations§
Source§impl AttributeValue
impl AttributeValue
Sourcepub fn as_str(&self) -> Cow<'_, str>
pub fn as_str(&self) -> Cow<'_, str>
Renders the value as text, the same way AOSP’s BinaryXmlPullParser does.
Nullis the empty string.- Bytes are lowercase hex or standard Base64.
IntHexandLongHexare signed, like Java’sInteger.toString(v, 16):0xCAFEBABErenders as-35014542.- Whole
FloatandDoublevalues keep a.0suffix.
The result is not XML-escaped.
§Examples
use android_abx::AttributeValue;
assert_eq!(AttributeValue::IntHex(0xff).as_str(), "ff");
assert_eq!(AttributeValue::IntHex(0xCAFEBABE).as_str(), "-35014542");
assert_eq!(AttributeValue::Double(1.0).as_str(), "1.0");
assert_eq!(AttributeValue::BytesHex(vec![0xab, 0x01]).as_str(), "ab01");Sourcepub fn as_int_hex(&self) -> Option<u32>
pub fn as_int_hex(&self) -> Option<u32>
Returns the value if this is IntHex, otherwise None.
Sourcepub fn as_long_hex(&self) -> Option<u64>
pub fn as_long_hex(&self) -> Option<u64>
Returns the value if this is LongHex, otherwise None.
Trait Implementations§
Source§impl Clone for AttributeValue
impl Clone for AttributeValue
Source§impl Debug for AttributeValue
impl Debug for AttributeValue
Source§impl PartialEq for AttributeValue
impl PartialEq for AttributeValue
impl StructuralPartialEq for AttributeValue
Auto Trait Implementations§
impl Freeze for AttributeValue
impl RefUnwindSafe for AttributeValue
impl Send for AttributeValue
impl Sync for AttributeValue
impl Unpin for AttributeValue
impl UnsafeUnpin for AttributeValue
impl UnwindSafe for AttributeValue
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