Skip to main content

NamedValue

Struct NamedValue 

Source
pub struct NamedValue { /* private fields */ }
Expand description

Named single value

Associates a human-readable name with a single Value, facilitating identification, retrieval, and display in configurations, parameter passing, and complex data structures.

§Features

  • Provides stable name identification for values
  • Exposes the inner Value through explicit accessors
  • Supports serde serialization and deserialization

§Use Cases

  • Configuration item encapsulation (e.g., "port", "timeout", etc.)
  • Named output of key values in logs/monitoring
  • Quick location by name in collections

§Examples

use qubit_value::{NamedValue, Value};

let named = NamedValue::new("flag", Value::Bool(true));
assert!(named.value().get_bool().unwrap());

The wrapper intentionally does not forward Value methods implicitly:

use qubit_value::{NamedValue, Value};

let named = NamedValue::new("flag", Value::Bool(true));
let _ = named.get_bool();

Implementations§

Source§

impl NamedValue

Source

pub fn new(name: impl Into<String>, value: Value) -> Self

Create a new named value

Creates a binding instance between a name and a value.

§Parameters
  • name - Name of the value
  • value - Content of the value
§Returns

Returns a newly created NamedValue instance

§Examples
use qubit_value::{NamedValue, Value};

let named = NamedValue::new("timeout", Value::Int32(30));
assert_eq!(named.name(), "timeout");
Source

pub fn decode_json_slice(input: &[u8]) -> Result<Self, ValueWireDecodeError>

Decodes a complete named scalar JSON document with default limits.

§Parameters
  • input - Complete UTF-8 JSON document to decode.
§Returns

The decoded named scalar.

§Errors

Returns a JSON, wire-contract, or resource-limit error.

Source

pub fn decode_json_slice_with_limits( input: &[u8], limits: WireLimits, ) -> Result<Self, ValueWireDecodeError>

Decodes a complete named scalar JSON document with explicit limits.

The wrapper name and nested scalar share one accounting session.

§Parameters
  • input - Complete UTF-8 JSON document to decode.
  • limits - Input and decoded-resource limits.
§Returns

The decoded named scalar.

§Errors

Returns a JSON, wire-contract, or resource-limit error.

Source

pub fn name(&self) -> &str

Get a reference to the name

Returns a read-only name slice bound to this value.

§Returns

Returns a string slice &str of the name

§Examples
use qubit_value::{NamedValue, Value};

let named = NamedValue::new("host", Value::String("localhost".to_string()));
assert_eq!(named.name(), "host");
Source

pub fn set_name(&mut self, name: impl Into<String>)

Set a new name

Updates the name bound to the current instance.

§Parameters
  • name - The new name
§Examples
use qubit_value::{NamedValue, Value};

let mut named = NamedValue::new("old_name", Value::Bool(true));
named.set_name("new_name");
assert_eq!(named.name(), "new_name");
Source

pub fn value(&self) -> &Value

Borrows the contained value.

§Returns

A shared reference to the contained Value.

Source

pub fn value_mut(&mut self) -> &mut Value

Mutably borrows the contained value.

§Returns

An exclusive reference to the contained Value.

Source

pub fn set_value(&mut self, value: Value)

Replaces the contained value.

§Parameters
  • value - New value to store under the existing name.
Source

pub fn into_parts(self) -> (String, Value)

Consumes this wrapper and returns its owned name and value.

§Returns

The (name, value) pair without cloning either component.

Trait Implementations§

Source§

impl Clone for NamedValue

Source§

fn clone(&self) -> NamedValue

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 NamedValue

Source§

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

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

impl<'de> Deserialize<'de> for NamedValue

Source§

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

Deserializes a named scalar value from the V1 wire contract.

Source§

impl Eq for NamedValue

Source§

impl From<NamedValue> for NamedMultiValues

Source§

fn from(named: NamedValue) -> Self

Construct NamedMultiValues from NamedValue

Reuses the name and promotes the single value to a MultiValues containing only one element.

Source§

impl Hash for NamedValue

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NamedValue

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Redact for NamedValue

Source§

fn redacted(&self) -> Redacted<'_, Self>
where Self: Sized,

Creates a borrowed view using a snapshot of the current default policy. Read more
Source§

fn redacted_with(&self, policy: &RedactionPolicy) -> Redacted<'_, Self>
where Self: Sized,

Creates a borrowed view using a snapshot of policy. Read more
Source§

impl Serialize for NamedValue

Source§

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

Serializes the name and its explicitly versioned scalar value.

Source§

impl StructuralPartialEq for NamedValue

Auto Trait Implementations§

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

Source§

fn into_value_default(self) -> T

Converts this argument into the default value. Read more
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 = 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.