Struct valuable::NamedValues

source ·
pub struct NamedValues<'a> { /* private fields */ }
Expand description

Set of values from a Structable or Enumerable with named fields.

Implementations§

source§

impl<'a> NamedValues<'a>

source

pub fn new( fields: &'a [NamedField<'a>], values: &'a [Value<'a>] ) -> NamedValues<'a>

Create a new NamedValues instance.

Both fields and values must be the same length.

Panics

The method panics if fields and values are different lengths.

Examples
use valuable::{NamedField, NamedValues, Value};

let fields = [
    NamedField::new("foo"),
    NamedField::new("bar")
];
let values = [
    Value::U32(123),
    Value::U32(456),
];

let named_values = NamedValues::new(&fields, &values);

assert_eq!(
    named_values.get(&fields[0]).unwrap().as_u32(),
    Some(123));
source

pub fn get(&self, field: &NamedField<'_>) -> Option<&Value<'_>>

Get a value using a NamedField reference.

Examples
use valuable::{NamedField, NamedValues, Value};

let fields = [
    NamedField::new("foo"),
    NamedField::new("bar")
];
let values = [
    Value::U32(123),
    Value::U32(456),
];

let named_values = NamedValues::new(&fields, &values);

assert_eq!(
    named_values.get(&fields[0]).unwrap().as_u32(),
    Some(123));
source

pub fn get_by_name(&self, name: impl AsRef<str>) -> Option<&Value<'_>>

Get a value using string.

Examples
use valuable::{NamedField, NamedValues, Value};

let fields = [
    NamedField::new("foo"),
    NamedField::new("bar")
];
let values = [
    Value::U32(123),
    Value::U32(456),
];

let named_values = NamedValues::new(&fields, &values);

assert_eq!(
    named_values.get_by_name("foo").unwrap().as_u32(),
    Some(123));
source

pub fn iter<'b>(&'b self) -> Iter<'a, 'b>

Iterate all name-value pairs.

Examples
use valuable::{NamedField, NamedValues, Value};

let fields = [
    NamedField::new("foo"),
    NamedField::new("bar")
];
let values = [
    Value::U32(123),
    Value::U32(456),
];

let named_values = NamedValues::new(&fields, &values);

for (field, value) in named_values.iter() {
    println!("{:?}: {:?}", field, value);
}
source

pub fn len(&self) -> usize

Returns the length of fields.

source

pub fn is_empty(&self) -> bool

Returns true if fields have a length of 0.

Trait Implementations§

source§

impl<'a> Debug for NamedValues<'a>

source§

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

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

impl<'a, 'b> IntoIterator for &'b NamedValues<'a>

§

type Item = (&'b NamedField<'a>, &'b Value<'a>)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, 'b>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for NamedValues<'a>

§

impl<'a> !Send for NamedValues<'a>

§

impl<'a> !Sync for NamedValues<'a>

§

impl<'a> Unpin for NamedValues<'a>

§

impl<'a> !UnwindSafe for NamedValues<'a>

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.