Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value { Null, Bool(bool), Int(i64), Float(f64), Text(String), Bytes(Bytes), List(Vec<Value>), Map(Fields), Tensor(Tensor), Image(Arc<DynamicImage>), Custom(Arc<dyn CustomValue>), }
Expand description

A value carried by a sample field.

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.
§

Null

Absent or JSON null.

§

Bool(bool)

A boolean.

§

Int(i64)

An integer, e.g. the contents of a .cls file.

§

Float(f64)

A floating point number.

§

Text(String)

Text, e.g. the contents of a .txt file.

§

Bytes(Bytes)

Undecoded (or deliberately raw) file contents.

§

List(Vec<Value>)

An ordered sequence, e.g. a JSON array or a collated batch column.

§

Map(Fields)

A string-keyed mapping, e.g. a JSON object or an .npz archive.

§

Tensor(Tensor)

A dense numeric array, e.g. from .npy or .ten.

§

Image(Arc<DynamicImage>)

Available on crate feature image only.

A decoded image.

§

Custom(Arc<dyn CustomValue>)

Anything else a user-supplied decoder produced.

Implementations§

Source§

impl Value

Source

pub fn custom<T: CustomValue>(value: T) -> Value

Wrap an arbitrary value so it can live inside a sample.

Source

pub fn type_name(&self) -> &'static str

A short type name, useful in error messages.

Source

pub fn as_bytes(&self) -> Option<&Bytes>

Borrow the raw bytes, if this value is undecoded.

Source

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

Borrow the text, if this value is a string.

Source

pub fn as_i64(&self) -> Option<i64>

Read this value as an integer, accepting Int, Bool and whole Floats.

Source

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

Read this value as a float, accepting Float and Int.

Source

pub fn as_list(&self) -> Option<&[Value]>

Borrow the list elements, if this value is a list.

Source

pub fn as_map(&self) -> Option<&Fields>

Borrow the map, if this value is a map.

Source

pub fn as_tensor(&self) -> Option<&Tensor>

Borrow the tensor, if this value is one.

Source

pub fn as_image(&self) -> Option<&DynamicImage>

Available on crate feature image only.

Borrow the decoded image, if this value is one.

Source

pub fn downcast_ref<T: Any>(&self) -> Option<&T>

Downcast a Value::Custom to a concrete type.

Source

pub fn expect_bytes(&self, key: &str) -> Result<&Bytes>

Like Value::as_bytes but produces a descriptive error.

Source

pub fn to_json(&self) -> Result<Value>

Available on crate feature json only.

Convert to a serde_json::Value where a faithful mapping exists.

Bytes are rejected rather than silently mangled; tensors become nested arrays of numbers; images and custom values are unsupported.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 From<&str> for Value

Source§

fn from(v: &str) -> Value

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Source§

fn from(v: Bytes) -> Value

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Value, BuildHasherDefault<Fnv1a>>> for Value

Source§

fn from(v: Fields) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Value

Converts to this type from the input type.
Source§

impl From<Tensor> for Value

Source§

fn from(v: Tensor) -> Value

Converts to this type from the input type.
Source§

impl From<Value> for Value

Available on crate feature json only.
Source§

fn from(v: Value) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

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

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Value

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(v: usize) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !Freeze for Value

§

impl !RefUnwindSafe for Value

§

impl !UnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CustomValue for T
where T: Any + Debug + Send + Sync,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Upcast so callers can downcast to the concrete type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.