Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value { Tensor { values: Arc<Vec<f64>>, shape: Vec<usize>, }, Text(Arc<str>), Json(Arc<Value>), Bytes(Arc<Vec<u8>>), Object(Arc<Vec<u8>>), Empty, }
Expand description

Typed values flowing between filters in a pipeline.

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

Tensor

Numeric tensor data (shape + flat data). values is wrapped in Arc so that cloning a Value is O(1).

Fields

§values: Arc<Vec<f64>>

Flat data in row-major order; Arc-shared, never mutated in place.

§shape: Vec<usize>

Dimension sizes; the product must equal values.len().

§

Text(Arc<str>)

UTF-8 text (Arc-wrapped for cheap cloning).

Distinct from Json(String): a prompt or completion is text, not a JSON document that happens to be a string. Keeping them apart means no round-trip through quoting/escaping on every hop, and lets a schema say “this edge carries text” — see crate::schema::DataType.

§

Json(Arc<Value>)

Structured JSON data (Arc-wrapped for cheap cloning).

§

Bytes(Arc<Vec<u8>>)

Raw bytes (Arc-wrapped for cheap cloning).

§

Object(Arc<Vec<u8>>)

Opaque serialized object (e.g. Python pickle). Soma passes it through without interpreting the contents. Used for efficient inter-filter data transfer when the producing and consuming runtimes share a serialization format.

§

Empty

Empty / void value

Implementations§

Source§

impl Value

Source

pub fn tensor(values: Vec<f64>, shape: Vec<usize>) -> Self

Create a tensor from flat row-major data and a shape.

Source

pub fn text(s: impl AsRef<str>) -> Self

Create a text value.

Source

pub fn json(val: Value) -> Self

Create a JSON value.

Source

pub fn bytes(data: Vec<u8>) -> Self

Create a raw bytes value.

Source

pub fn object(data: Vec<u8>) -> Self

Create an opaque serialized object (e.g. a Python pickle).

Source

pub fn is_empty(&self) -> bool

Is this the Value::Empty variant?

Source

pub fn as_tensor(&self) -> Option<(&[f64], &[usize])>

Try to extract tensor data.

Source

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

Try to extract text.

A Json string counts: a filter that returns "hello" as JSON and one that returns it as text should both satisfy a consumer wanting text.

Source

pub fn as_json(&self) -> Option<&Value>

Try to extract JSON value.

Source

pub fn to_plain_json(&self) -> Value

Natural JSON form for user-facing fan-in: tensors become (nested) number arrays, Json unwraps, Empty is null. This is what a multi-predecessor node receives per upstream branch — never the internal serde-tagged encoding.

Source

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

Short name of the variant, for error messages.

Unlike Display this never renders the payload, so it is safe to put in an error that may reach a log — a JSON value can hold a prompt.

Source

pub fn size(&self) -> usize

Number of elements (for tensors) or bytes.

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<'de> Deserialize<'de> for Value

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Value

Source§

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

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

impl From<Value> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for VirtualValue

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for Value

Source§

fn from(values: Vec<f64>) -> Self

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

impl Serialize for Value

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> AsAny for T
where T: Any,

Source§

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

The receiver as &dyn Any, ready for downcast_ref.
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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.