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
impl Value
Sourcepub fn infer_type(&self) -> ValueType
pub fn infer_type(&self) -> ValueType
Infer the most specific declared type for this value.
pub fn is_null(&self) -> bool
pub fn as_str(&self) -> Option<&str>
Sourcepub fn expose_secret(&self) -> Option<&str>
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).
Sourcepub fn require_secret(&self) -> Result<&str, SecretError>
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.
Sourcepub fn redacted_secret() -> Value
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.
Sourcepub fn is_redacted_secret(&self) -> bool
pub fn is_redacted_secret(&self) -> bool
Whether this is a Value::redacted_secret.
Sourcepub fn to_snapshot_value(&self) -> Value
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.
Sourcepub fn from_snapshot_value(self) -> Value
pub fn from_snapshot_value(self) -> Value
Inverse of Value::to_snapshot_value: secret markers become redacted secrets.
pub fn as_bool(&self) -> Option<bool>
pub fn as_i64(&self) -> Option<i64>
pub fn as_f64(&self) -> Option<f64>
pub fn as_array(&self) -> Option<&[Value]>
pub fn as_object(&self) -> Option<&Map>
pub fn as_file(&self) -> Option<&File>
Sourcepub fn array(items: impl IntoIterator<Item = Value>) -> Value
pub fn array(items: impl IntoIterator<Item = Value>) -> Value
Build an array value.
Sourcepub fn object<K: Into<String>>(
entries: impl IntoIterator<Item = (K, Value)>,
) -> Value
pub fn object<K: Into<String>>( entries: impl IntoIterator<Item = (K, Value)>, ) -> Value
Build an object value.
Sourcepub fn get_path<S: AsRef<str>>(&self, path: &[S]) -> Option<Value>
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.
Sourcepub fn to_text(&self) -> String
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.
Sourcepub fn to_text_exposed(&self) -> String
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.
Sourcepub fn from_json(json: Value) -> Value
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.
Sourcepub fn from_json_trusted(json: Value) -> Value
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.