Enum mpris::MetadataValue
source · pub enum MetadataValue {
}
Expand description
Holds a dynamically-typed metadata value.
You will need to type-check this at runtime in order to use the value.
Variants§
String(String)
Value is a string.
I16(i16)
Value is a 16-bit integer.
I32(i32)
Value is a 32-bit integer.
I64(i64)
Value is a 64-bit integer.
U8(u8)
Value is an unsigned 8-bit integer.
U16(u16)
Value is an unsigned 16-bit integer.
U32(u32)
Value is an unsigned 32-bit integer.
U64(u64)
Value is an unsigned 64-bit integer.
F64(f64)
Value is a 64-bit float.
Bool(bool)
Value is a boolean.
Array(Vec<Value>)
Value is an array of other values.
Map(HashMap<String, Value>)
Value is a map of other values.
Unsupported
Unsupported value type.
Implementations§
source§impl Value
impl Value
sourcepub fn kind(&self) -> ValueKind
pub fn kind(&self) -> ValueKind
Returns a simple enum representing the type of value that this value holds.
Examples
use mpris::MetadataValueKind;
if let Some(value) = metadata.get(key_name) {
match value.kind() {
MetadataValueKind::String => println!("{} is a string", key_name),
MetadataValueKind::I16 |
MetadataValueKind::I32 |
MetadataValueKind::I64 |
MetadataValueKind::U8 |
MetadataValueKind::U16 |
MetadataValueKind::U32 |
MetadataValueKind::U64 => println!("{} is an integer", key_name),
MetadataValueKind::F64 => println!("{} is a float", key_name),
MetadataValueKind::Bool => println!("{} is a boolean", key_name),
MetadataValueKind::Array => println!("{} is an array", key_name),
MetadataValueKind::Map => println!("{} is a map", key_name),
MetadataValueKind::Unsupported => println!("{} is not a supported type", key_name),
}
} else {
println!("Metadata does not have a {} key", key_name);
}
sourcepub fn as_str_array(&self) -> Option<Vec<&str>>
pub fn as_str_array(&self) -> Option<Vec<&str>>
Returns the value as a Some(Vec<&str>)
if it is a MetadataValue::Array
. Any elements
that are not MetadataValue::String
values will be ignored.
sourcepub fn as_u8(&self) -> Option<u8>
pub fn as_u8(&self) -> Option<u8>
Returns the value as a Some(u8)
if it is a MetadataValue::U8
, or None
otherwise.
sourcepub fn as_u16(&self) -> Option<u16>
pub fn as_u16(&self) -> Option<u16>
Returns the value as a Some(u16)
if it is an unsigned int smaller than or equal to u16,
or None
otherwise.
sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Returns the value as a Some(u32)
if it is an unsigned int smaller than or equal to u32,
or None
otherwise.
sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Returns the value as a Some(u64)
if it is an unsigned int smaller than or equal to u64,
or None
otherwise.
sourcepub fn as_i16(&self) -> Option<i16>
pub fn as_i16(&self) -> Option<i16>
Returns the value as a Some(i16)
if it is a signed integer smaller than or equal to i16,
or None
otherwise.
sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
Returns the value as a Some(i32)
if it is a signed integer smaller than or equal to i32,
or None
otherwise.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the value as a Some(i64)
if it is a signed integer smaller than or equal to i64,
or None
otherwise.
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the value as a Some(f64)
if it is a MetadataValue::F64
, or None
otherwise.
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the value as a Some(bool)
if it is a MetadataValue::Bool
, or None
otherwise.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the value as a Some(&str)
if it is a MetadataValue::String
, or None
otherwise.
sourcepub fn as_string(&self) -> Option<&String>
pub fn as_string(&self) -> Option<&String>
Returns the value as a Some(&String)
if it is a MetadataValue::String
, or None
otherwise.
sourcepub fn as_map(&self) -> Option<&HashMap<String, Value>>
pub fn as_map(&self) -> Option<&HashMap<String, Value>>
Returns the value as a Some(&HashMap<String, Value>)
if it is a MetadataValue::Map
, or None
otherwise.
sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
Returns the value as a Some(&Vec<Value>)
if it is a MetadataValue::Array
, or None
otherwise.
sourcepub fn into_u8(self) -> Option<u8>
pub fn into_u8(self) -> Option<u8>
Consumes self
and returns the inner value as a Some(u8)
if it is a MetadataValue::U8
, or None
otherwise.
sourcepub fn into_u16(self) -> Option<u16>
pub fn into_u16(self) -> Option<u16>
Consumes self
and returns the inner value as a Some(u16)
if it is an unsigned integer
smaller than or equal to u16, or None
otherwise.
sourcepub fn into_u32(self) -> Option<u32>
pub fn into_u32(self) -> Option<u32>
Consumes self
and returns the inner value as a Some(u32)
if it is an unsigned integer
smaller than or equal to u32, or None
otherwise.
sourcepub fn into_u64(self) -> Option<u64>
pub fn into_u64(self) -> Option<u64>
Consumes self
and returns the inner value as a Some(u64)
if it is an unsigned integer
smaller than or equal to u64, or None
otherwise.
sourcepub fn into_i16(self) -> Option<i16>
pub fn into_i16(self) -> Option<i16>
Consumes self
and returns the inner value as a Some(i16)
if it is a signed integer
smaller than or equal to i16, or None
otherwise.
sourcepub fn into_i32(self) -> Option<i32>
pub fn into_i32(self) -> Option<i32>
Consumes self
and returns the inner value as a Some(i32)
if it is a signed integer
smaller than or equal to i32, or None
otherwise.
sourcepub fn into_i64(self) -> Option<i64>
pub fn into_i64(self) -> Option<i64>
Consumes self
and returns the inner value as a Some(i64)
if it is a signed integer
smaller than or equal to i64, or None
otherwise.
sourcepub fn into_f64(self) -> Option<f64>
pub fn into_f64(self) -> Option<f64>
Consumes self
and returns the inner value as a Some(f64)
if it is a
MetadataValue::F64
, or None
otherwise.
sourcepub fn into_bool(self) -> Option<bool>
pub fn into_bool(self) -> Option<bool>
Consumes self
and returns the inner value as a Some(bool)
if it is a
MetadataValue::Bool
, or None
otherwise.
sourcepub fn into_string(self) -> Option<String>
pub fn into_string(self) -> Option<String>
Consumes self
and returns the inner value as a Some(String)
if it is a
MetadataValue::String
, or None
otherwise.
sourcepub fn into_map(self) -> Option<HashMap<String, Value>>
pub fn into_map(self) -> Option<HashMap<String, Value>>
Consumes self
and returns the inner value as a Some(HashMap<String, Value>)
if it is a
MetadataValue::Map
, or None
otherwise.
sourcepub fn into_array(self) -> Option<Vec<Value>>
pub fn into_array(self) -> Option<Vec<Value>>
Consumes self
and returns the inner value as a Some(Vec<Value>)
if it is a
MetadataValue::Array
, or None
otherwise.