Enum valuable::Slice

source ·
#[non_exhaustive]
pub enum Slice<'a> {
Show 19 variants Bool(&'a [bool]), Char(&'a [char]), F32(&'a [f32]), F64(&'a [f64]), I8(&'a [i8]), I16(&'a [i16]), I32(&'a [i32]), I64(&'a [i64]), I128(&'a [i128]), Isize(&'a [isize]), Str(&'a [&'a str]), String(&'a [String]), U8(&'a [u8]), U16(&'a [u16]), U32(&'a [u32]), U64(&'a [u64]), U128(&'a [u128]), Usize(&'a [usize]), Unit(&'a [()]),
}
Expand description

A slice containing primitive values.

The Slice enum is used to pass multiple primitive-values to the visitor. This is used as an optimization when visiting Listable types to avoid a dynamic dispatch call to Visit for each element in the collection.

Slice instances are usually not created explicitly. Instead, they are created when calling Valuable::visit_slice().

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Bool(&'a [bool])

A slice containing bool values.

Examples

use valuable::Slice;

let v = Slice::Bool(&[true, true, false]);
§

Char(&'a [char])

A slice containing char values.

Examples

use valuable::Slice;

let v = Slice::Char(&['a', 'b', 'c']);
§

F32(&'a [f32])

A slice containing f32 values.

Examples

use valuable::Slice;

let v = Slice::F32(&[3.1415, 2.71828]);
§

F64(&'a [f64])

A slice containing f64 values.

Examples

use valuable::Slice;

let v = Slice::F64(&[3.1415, 2.71828]);
§

I8(&'a [i8])

A slice containing i8 values.

Examples

use valuable::Slice;

let v = Slice::I8(&[1, 1, 2, 3, 5]);
§

I16(&'a [i16])

A slice containing i16 values.

Examples

use valuable::Slice;

let v = Slice::I16(&[1, 1, 2, 3, 5]);
§

I32(&'a [i32])

A slice containing I32 values.

Examples

use valuable::Slice;

let v = Slice::I32(&[1, 1, 2, 3, 5]);
§

I64(&'a [i64])

A slice containing I64 values.

Examples

use valuable::Slice;

let v = Slice::I64(&[1, 1, 2, 3, 5]);
§

I128(&'a [i128])

A slice containing I128 values.

Examples

use valuable::Slice;

let v = Slice::I128(&[1, 1, 2, 3, 5]);
§

Isize(&'a [isize])

A slice containing isize values.

Examples

use valuable::Slice;

let v = Slice::Isize(&[1, 1, 2, 3, 5]);
§

Str(&'a [&'a str])

A slice containing str values.

Examples

use valuable::Slice;

let v = Slice::Str(&["foo", "bar", "baz"]);
§

String(&'a [String])

A slice containing String values.

Examples

use valuable::Slice;

let v = Slice::String(&["foo".to_string(), "bar".to_string()]);
§

U8(&'a [u8])

A slice containing u8 values.

Examples

use valuable::Slice;

let v = Slice::U8(&[1, 1, 2, 3, 5]);
§

U16(&'a [u16])

A slice containing u16 values.

Examples

use valuable::Slice;

let v = Slice::U16(&[1, 1, 2, 3, 5]);
§

U32(&'a [u32])

A slice containing u32 values.

Examples

use valuable::Slice;

let v = Slice::U32(&[1, 1, 2, 3, 5]);
§

U64(&'a [u64])

A slice containing u64 values.

Examples

use valuable::Slice;

let v = Slice::U64(&[1, 1, 2, 3, 5]);
§

U128(&'a [u128])

A slice containing u128 values.

Examples

use valuable::Slice;

let v = Slice::U128(&[1, 1, 2, 3, 5]);
§

Usize(&'a [usize])

A slice containing usize values.

Examples

use valuable::Slice;

let v = Slice::Usize(&[1, 1, 2, 3, 5]);
§

Unit(&'a [()])

A slice containing () values.

Examples

use valuable::Slice;

let v = Slice::Unit(&[(), (), ()]);

Implementations§

source§

impl<'a> Slice<'a>

source

pub fn len(&self) -> usize

Returns the number of elements in the slice

Examples
use valuable::Slice;

let slice = Slice::U32(&[1, 1, 2, 3, 5]);
assert_eq!(5, slice.len());
source

pub fn is_empty(&self) -> bool

Returns true if the slice is not empty.

Examples
use valuable::Slice;

let slice = Slice::U32(&[1, 1, 2, 3, 5]);
assert!(!slice.is_empty());
let slice = Slice::U32(&[]);
assert!(slice.is_empty());
source

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

Returns an iterator over the slice.

Examples
use valuable::Slice;

let slice = Slice::U32(&[1, 1, 2, 3, 5]);

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

Trait Implementations§

source§

impl Debug for Slice<'_>

source§

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

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

impl<'a> IntoIterator for &Slice<'a>

§

type Item = Value<'a>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for Slice<'a>

§

type Item = Value<'a>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

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 Slice<'a>

§

impl<'a> Send for Slice<'a>

§

impl<'a> Sync for Slice<'a>

§

impl<'a> Unpin for Slice<'a>

§

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