Enum mpris::MetadataValue

source ·
pub enum MetadataValue {
Show 13 variants String(String), I16(i16), I32(i32), I64(i64), U8(u8), U16(u16), U32(u32), U64(u64), F64(f64), Bool(bool), Array(Vec<Value>), Map(HashMap<String, Value>), Unsupported,
}
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

source

pub fn is_string(&self) -> bool

Is this Value a String?

source

pub fn is_i16(&self) -> bool

Is this Value a I16?

source

pub fn is_i32(&self) -> bool

Is this Value a I32?

source

pub fn is_i64(&self) -> bool

Is this Value a I64?

source

pub fn is_u8(&self) -> bool

Is this Value a U8?

source

pub fn is_u16(&self) -> bool

Is this Value a U16?

source

pub fn is_u32(&self) -> bool

Is this Value a U32?

source

pub fn is_u64(&self) -> bool

Is this Value a U64?

source

pub fn is_f64(&self) -> bool

Is this Value a F64?

source

pub fn is_bool(&self) -> bool

Is this Value a Bool?

source

pub fn is_array(&self) -> bool

Is this Value a Array?

source

pub fn is_map(&self) -> bool

Is this Value a Map?

source

pub fn is_unsupported(&self) -> bool

Is this Value a Unsupported?

source§

impl Value

source

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);
}
source

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.

source

pub fn as_u8(&self) -> Option<u8>

Returns the value as a Some(u8) if it is a MetadataValue::U8, or None otherwise.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn as_f64(&self) -> Option<f64>

Returns the value as a Some(f64) if it is a MetadataValue::F64, or None otherwise.

source

pub fn as_bool(&self) -> Option<bool>

Returns the value as a Some(bool) if it is a MetadataValue::Bool, or None otherwise.

source

pub fn as_str(&self) -> Option<&str>

Returns the value as a Some(&str) if it is a MetadataValue::String, or None otherwise.

source

pub fn as_string(&self) -> Option<&String>

Returns the value as a Some(&String) if it is a MetadataValue::String, or None otherwise.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Arg for Value

source§

const ARG_TYPE: ArgType = ArgType::Variant

The corresponding D-Bus argument type code.
source§

fn signature() -> Signature<'static>

The corresponding D-Bus type signature for this type.
source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'__enum_kinds1> From<&'__enum_kinds1 Value> for ValueKind

source§

fn from(_value: &'__enum_kinds1 Value) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for Value

source§

fn from(string: &'a str) -> Value

Converts to this type from the input type.
source§

impl From<HashMap<String, Value, RandomState>> for Value

Convert into Map variant.

source§

fn from(v: HashMap<String, Value>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Value

Convert into String variant.

source§

fn from(v: String) -> Self

Converts to this type from the input type.
source§

impl<'__enum_kinds1> From<Value> for ValueKind

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Value, Global>> for Value

Convert into Array variant.

source§

fn from(v: Vec<Value>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

Convert into Bool variant.

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

Convert into F64 variant.

source§

fn from(v: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Value

Convert into I16 variant.

source§

fn from(v: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

Convert into I32 variant.

source§

fn from(v: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

Convert into I64 variant.

source§

fn from(v: i64) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Value

Convert into U16 variant.

source§

fn from(v: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

Convert into U32 variant.

source§

fn from(v: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Value

Convert into U64 variant.

source§

fn from(v: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Value

Convert into U8 variant.

source§

fn from(v: u8) -> Self

Converts to this type from the input type.
source§

impl<'a> Get<'a> for Value

source§

fn get(i: &mut Iter<'_>) -> Option<Self>

Performs the get operation.
source§

impl PartialEq<Value> for Value

source§

fn eq(&self, other: &Value) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.