Struct kserd::ds::Accessor[][src]

pub struct Accessor<T>(_);

Accessor provides a wrapper around a value, adding additional accessing methods.

Containers

A container accessor can be constructed through Value::cntr or Value::cntr_mut. These give you immutable or mutable access to the underlying map store, along with additional methods for accessing an entry if it matches the name + the type of Value.

Example

let mut cntr = Value::new_cntr(vec![
    ("a", Kserd::new_str("Hello")),
    ("b", Kserd::new_num(101))
]).unwrap();

let mut accessor = cntr.cntr_mut().unwrap();

assert_eq!(accessor.get_str("a"), Some("Hello"));
assert_eq!(accessor.get_str("b"), None); // not a string
assert_eq!(accessor.get_num("b"), Some(101.into()));

// mutating is also possible
accessor.get_str_mut("a").map(|s| s.push_str(", world!"));

assert_eq!(accessor.get_str("a"), Some("Hello, world!"));

Implementations

impl<'a, T> Accessor<T> where
    T: Deref<Target = BTreeMap<Kstr<'a>, Kserd<'a>>>, 
[src]

Immutable access to a container’s fields.

pub fn get_unit<K: ?Sized>(&self, name: &K) -> Option<()> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a unit value along the key name.

pub fn get_bool<K: ?Sized>(&self, name: &K) -> Option<bool> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a boolean value along the key name.

pub fn get_num<K: ?Sized>(&self, name: &K) -> Option<Number> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a numeric value along the key name.

pub fn get_str<'b, K: ?Sized>(&'b self, name: &K) -> Option<&'b str> where
    'a: 'b,
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a string value along the key name.

pub fn get_barr<'b, K: ?Sized>(&'b self, name: &K) -> Option<&'b [u8]> where
    'a: 'b,
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a byte array value along the key name.

pub fn get_tuple<K: ?Sized>(&self, name: &K) -> Option<&Vec<Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a tuple value along the key name.

pub fn get_seq<K: ?Sized>(&self, name: &K) -> Option<&Vec<Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a sequence value along the key name.

pub fn get_tuple_or_seq<K: ?Sized>(&self, name: &K) -> Option<&Vec<Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a tuple or sequence value along the key name.

pub fn get_cntr<K: ?Sized>(
    &self,
    name: &K
) -> Option<Accessor<&BTreeMap<Kstr<'a>, Kserd<'a>>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a container value along the key name.

pub fn get_map<K: ?Sized>(
    &self,
    name: &K
) -> Option<&BTreeMap<Kserd<'a>, Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a map value along the key name.

impl<'a, T> Accessor<T> where
    T: DerefMut<Target = BTreeMap<Kstr<'a>, Kserd<'a>>>, 
[src]

Mutable access to a container’s fields.

pub fn get_bool_mut<'b, K: ?Sized>(
    &'b mut self,
    name: &K
) -> Option<&'b mut bool> where
    'a: 'b,
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a boolean value along the key name.

pub fn get_num_mut<'b, K: ?Sized>(
    &'b mut self,
    name: &K
) -> Option<&'b mut Number> where
    'a: 'b,
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a numeric value along the key name.

pub fn get_str_mut<'b, K: ?Sized>(
    &'b mut self,
    name: &K
) -> Option<&'b mut String> where
    'a: 'b,
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a string value along the key name.

pub fn get_barr_mut<'b, K: ?Sized>(
    &'b mut self,
    name: &K
) -> Option<&'b mut Vec<u8>> where
    'a: 'b,
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a byte array value along the key name.

pub fn get_tuple_mut<K: ?Sized>(
    &mut self,
    name: &K
) -> Option<&mut Vec<Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a tuple value along the key name.

pub fn get_seq_mut<K: ?Sized>(
    &mut self,
    name: &K
) -> Option<&mut Vec<Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a sequence value along the key name.

pub fn get_tuple_or_seq_mut<K: ?Sized>(
    &mut self,
    name: &K
) -> Option<&mut Vec<Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a tuple or sequence value along the key name.

pub fn get_cntr_mut<K: ?Sized>(
    &mut self,
    name: &K
) -> Option<Accessor<&mut BTreeMap<Kstr<'a>, Kserd<'a>>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a container value along the key name.

pub fn get_map_mut<K: ?Sized>(
    &mut self,
    name: &K
) -> Option<&mut BTreeMap<Kserd<'a>, Kserd<'a>>> where
    K: Ord,
    Kstr<'a>: Borrow<K>, 
[src]

Returns if the container has a map value along the key name.

Trait Implementations

impl<T: Debug> Debug for Accessor<T>[src]

impl<T> Deref for Accessor<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> DerefMut for Accessor<T>[src]

impl<T: PartialEq> PartialEq<Accessor<T>> for Accessor<T>[src]

impl<T> StructuralPartialEq for Accessor<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Accessor<T> where
    T: RefUnwindSafe

impl<T> Send for Accessor<T> where
    T: Send

impl<T> Sync for Accessor<T> where
    T: Sync

impl<T> Unpin for Accessor<T> where
    T: Unpin

impl<T> UnwindSafe for Accessor<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.