Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 15 variants None, Bool(bool), Int(i64), BigInt(Vec<u8>), Float(f64), Complex(Complex64), Str(String), Bytes(Vec<u8>), List(Vec<Value>), Tuple(Vec<Value>), Set(Vec<Value>), Dict(Dict), Array(Array), Frame(Frame), Object(PyObject),
}
Expand description

A decoded Python value.

Basic Python types land on basic owned, mutable Rust types; np.ndarray and torch.Tensor land on Array (backed by ndarray::ArrayD); pandas.DataFrame and polars.DataFrame land on Frame.

Variants§

§

None

Python None.

§

Bool(bool)

Booleans, one byte each, as in numpy bool_.

§

Int(i64)

Python int that fits in 64 bits.

§

BigInt(Vec<u8>)

Arbitrary precision int, little-endian two’s complement.

§

Float(f64)

A Python float.

§

Complex(Complex64)

A Python complex.

§

Str(String)

Fixed-width UTF-32 text, the inner value being the character count.

§

Bytes(Vec<u8>)

Fixed-width byte string, the inner value being the length.

§

List(Vec<Value>)

A Python list.

§

Tuple(Vec<Value>)

A Python tuple.

§

Set(Vec<Value>)

A Python set or frozenset.

§

Dict(Dict)

A Python dict, insertion order preserved.

§

Array(Array)

np.ndarray, torch.Tensor, HDF5 dataset, npy payload.

§

Frame(Frame)

pandas.DataFrame, polars.DataFrame, numpy record array.

§

Object(PyObject)

Anything else, captured structurally without executing Python.

Implementations§

Source§

impl Value

Source

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

&str view for Value::Str.

Source

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

Numeric view; integers and bools widen to f64.

Source

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

Borrow the contents as i64, when the type matches.

Source

pub fn as_array(&self) -> Option<&Array>

Borrow the contents as array, when the type matches.

Source

pub fn as_array_mut(&mut self) -> Option<&mut Array>

Mutable array view — scale or normalise weights before loading them.

Source

pub fn as_dict(&self) -> Option<&Dict>

Borrow the contents as dict, when the type matches.

Source

pub fn as_dict_mut(&mut self) -> Option<&mut Dict>

Borrow the contents as dict mut, when the type matches.

Source

pub fn as_frame(&self) -> Option<&Frame>

Borrow the contents as frame, when the type matches.

Source

pub fn as_frame_mut(&mut self) -> Option<&mut Frame>

Borrow the contents as frame mut, when the type matches.

Source

pub fn as_object(&self) -> Option<&PyObject>

Borrow the contents as object, when the type matches.

Source

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

Short human-readable type name, handy in error messages.

Source

pub fn arrays_mut(&mut self) -> Vec<&mut Array>

Depth-first walk over every Array contained anywhere in the value.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

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<Array> for Value

Source§

fn from(v: Array) -> Value

Converts to this type from the input type.
Source§

impl From<Dict> for Value

Source§

fn from(v: Dict) -> Value

Converts to this type from the input type.
Source§

impl From<Frame> for Value

Source§

fn from(v: Frame) -> Value

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

fn from(v: Option<T>) -> Value

Converts to this type from the input type.
Source§

impl From<PyObject> for Value

Source§

fn from(v: PyObject) -> 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<Vec<u8>> for Value

Source§

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

A byte vector becomes bytes, matching what Python would pickle. For a u8 array, build an Array::U8 and convert that instead.

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<i8> for Value

Source§

fn from(v: i8) -> Value

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(v: i16) -> 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<u8> for Value

Source§

fn from(v: u8) -> Value

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(v: u16) -> Value

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.