Enum valuable::Fields

source ·
pub enum Fields<'a> {
    Named(&'a [NamedField<'a>]),
    Unnamed(usize),
}
Expand description

Data stored within a Structable or an Enumerable.

Variants§

§

Named(&'a [NamedField<'a>])

Named fields

§

Unnamed(usize)

Unnamed (positional) fields or unit

The usize value represents the number of fields.

Implementations§

source§

impl Fields<'_>

source

pub const fn is_named(&self) -> bool

Returns true if the fields are named.

Examples

Named fields

use valuable::Fields;

let fields = Fields::Named(&[]);
assert!(fields.is_named());

Unnamed fields

use valuable::Fields;

let fields = Fields::Unnamed(2);
assert!(!fields.is_named());
source

pub const fn is_unnamed(&self) -> bool

Returns true if the fields are unnamed.

Examples

Named fields

use valuable::Fields;

let fields = Fields::Named(&[]);
assert!(!fields.is_unnamed());

Unnamed fields

use valuable::Fields;

let fields = Fields::Unnamed(3);
assert!(fields.is_unnamed());
source

pub const fn len(&self) -> usize

Returns the number of fields.

Examples

Named fields

use valuable::{Fields, NamedField};

let fields = &[
    NamedField::new("alice"),
    NamedField::new("bob"),
];
let fields = Fields::Named(fields);

assert_eq!(fields.len(), 2);

Unnamed fields

use valuable::Fields;

let fields = Fields::Unnamed(2);
assert_eq!(fields.len(), 2);
source

pub const fn is_empty(&self) -> bool

Returns true if this set of fields defines no fields.

Examples

Named fields

use valuable::{Fields, NamedField};

let fields = &[
    NamedField::new("alice"),
    NamedField::new("bob"),
];
let non_empty = Fields::Named(fields);

let empty = Fields::Named(&[]);

assert!(!non_empty.is_empty());
assert!(empty.is_empty());

Unnamed fields

use valuable::Fields;

let non_empty = Fields::Unnamed(2);
let empty = Fields::Unnamed(0);

assert!(!non_empty.is_empty());
assert!(empty.is_empty());

Trait Implementations§

source§

impl<'a> Debug for Fields<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Fields<'a>

§

impl<'a> Send for Fields<'a>

§

impl<'a> Sync for Fields<'a>

§

impl<'a> Unpin for Fields<'a>

§

impl<'a> UnwindSafe for Fields<'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.