Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Int(i64),
    Float(f64),
    String(Arc<str>),
    Secret(Arc<str>),
    Array(Arc<Vec<Value>>),
    Object(Arc<Map>),
    File(Arc<File>),
}
Expand description

A dynamic runtime value.

Variants§

§

Null

Absent / null.

§

Bool(bool)

§

Int(i64)

§

Float(f64)

§

String(Arc<str>)

§

Secret(Arc<str>)

A sensitive string. Never serialized in plaintext.

§

Array(Arc<Vec<Value>>)

§

Object(Arc<Map>)

§

File(Arc<File>)

Implementations§

Source§

impl Value

Source

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

Short type name used in error messages.

Source

pub fn infer_type(&self) -> ValueType

Infer the most specific declared type for this value.

Source

pub fn is_null(&self) -> bool

Source

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

Source

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

Raw string contents, including secrets. Use only where the plaintext is required (e.g. an outgoing HTTP header), never for logging.

Returns None for a redacted secret (see Value::redacted_secret).

Source

pub fn require_secret(&self) -> Result<&str, SecretError>

Like Value::expose_secret, but explains why the plaintext is unavailable. Nodes that must transmit a secret should use this so a redacted secret fails loudly instead of sending an empty or masked value.

Source

pub fn redacted_secret() -> Value

A secret whose plaintext is not available (restored from a snapshot). It renders masked, exposes nothing and fails Value::require_secret.

Source

pub fn is_redacted_secret(&self) -> bool

Whether this is a Value::redacted_secret.

Source

pub fn to_snapshot_value(&self) -> Value

Persistable form of this value: every secret (at any depth) becomes the marker object {"$secret": "redacted"}, so neither plaintext nor a mask string that could be mistaken for data is written to a snapshot.

Source

pub fn from_snapshot_value(self) -> Value

Inverse of Value::to_snapshot_value: secret markers become redacted secrets.

Source

pub fn as_bool(&self) -> Option<bool>

Source

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

Source

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

Source

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

Source

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

Source

pub fn as_file(&self) -> Option<&File>

Source

pub fn is_empty(&self) -> bool

Whether the value is “empty” in the condition-operator sense.

Source

pub fn array(items: impl IntoIterator<Item = Value>) -> Value

Build an array value.

Source

pub fn object<K: Into<String>>( entries: impl IntoIterator<Item = (K, Value)>, ) -> Value

Build an object value.

Source

pub fn get_path<S: AsRef<str>>(&self, path: &[S]) -> Option<Value>

Descend into the value along a path. Objects are indexed by key, arrays by decimal index (negative indexes count from the end), and files expose their attributes. Returns None when any hop is missing.

Source

pub fn to_text(&self) -> String

Plain-text rendering used when a value is interpolated into a text template.

Strings render raw, numbers and booleans in JSON form, objects/arrays as compact JSON, files as their URL or name, null as empty text, and secrets are masked.

Source

pub fn to_text_exposed(&self) -> String

Like Value::to_text, but reveals secrets. Only for nodes that must transmit the plaintext (HTTP auth headers, code sandbox inputs). A redacted secret renders as empty text.

Source

pub fn from_json(json: Value) -> Value

Convert from an untrusted JSON value (HTTP bodies, tool results, model output). Never creates Value::File: objects with a FILE_MARKER_KEY stay plain objects, so remote data cannot forge file references.

Source

pub fn from_json_trusted(json: Value) -> Value

Convert from trusted JSON (snapshots, host-supplied inputs). Objects carrying the FILE_MARKER_KEY that decode as a File become files. The Deserialize impl of Value follows the same trusted rule.

Source§

impl Value

Source

pub fn to_json(&self) -> Value

Convert to a JSON value. Secrets are masked.

Source

pub fn to_json_exposed(&self) -> Value

Convert to JSON revealing secrets. Only for trusted sinks such as a code sandbox. A redacted secret becomes null.

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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<File> for Value

Source§

fn from(f: File) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(m: Map) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

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

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(i: i64) -> Self

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

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move 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<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> 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.