Skip to main content

Source

Trait Source 

Source
pub trait Source: Sized {
    // Required methods
    fn kind(&self) -> &'static str;
    fn is_null(&self) -> bool;
    fn is_object(&self) -> bool;
    fn as_bool(&self) -> Option<bool>;
    fn as_text(&self) -> Option<&str>;
    fn as_float(&self) -> Option<f64>;
    fn as_items(&self) -> Option<&[Self]>;
    fn field(&self, name: &str) -> Option<&Self>;
    fn entries(&self) -> Vec<(&str, &Self)>;
    fn as_integer(&self, path: &str) -> Result<i128, ProbeError>;
    fn as_float128(&self, path: &str) -> Result<Float128, ProbeError>;
    fn render(&self) -> String;
}
Expand description

A value the write direction can be executed against.

The accessors answer None where the value is not of that shape; the refusal, with its path, is crate::contract’s to build.

Required Methods§

Source

fn kind(&self) -> &'static str

A name for what this value is, for a refusal that says what was there rather than only what was wanted.

Source

fn is_null(&self) -> bool

Whether this value is the representation’s explicit nothing.

Never a value and never an absence — see crate::contract::reject_null. A representation with no such thing answers false and the rule costs it nothing.

Source

fn is_object(&self) -> bool

Whether this value is an aggregate with named fields.

Asked before Self::entries so that a walk over a hundred-member sample does not build a list to find out.

Source

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

true or false.

Source

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

The text this value carries.

Source

fn as_float(&self) -> Option<f64>

The floating value this value carries.

Source

fn as_items(&self) -> Option<&[Self]>

The elements of a sequence, an array or a map.

Source

fn field(&self, name: &str) -> Option<&Self>

One named field, or None where the value has no such field — including where it is not an aggregate at all.

Source

fn entries(&self) -> Vec<(&str, &Self)>

Every named field, in the order the representation holds them.

Empty for a value that is not an aggregate, which Self::is_object is what tells apart.

Source

fn as_integer(&self, path: &str) -> Result<i128, ProbeError>

The integer this value carries, exactly.

A representation that cannot carry every integer exactly refuses the spellings it cannot, here, naming what it wants instead. It is not crate::contract’s rule to state: the range an IDL primitive admits is the type’s business and is checked in crate::contract::integer_for, which asks this first.

§Errors

ProbeError::Mismatch, naming path.

Source

fn as_float128(&self, path: &str) -> Result<Float128, ProbeError>

The long double this value carries, exactly.

Separate from Self::as_float for the reason Self::as_integer is separate from a number: sixty of a binary128 significand’s 113 bits do not survive a double, so a representation whose only number is one has to accept the value in some other form and say so here.

§Errors

ProbeError::Mismatch, naming path.

Source

fn render(&self) -> String

The one form two implementations’ values can be compared in.

A pairwise run compares what came out of B against what went into A, and a representation usually has more than one way to write the same value. This is the one it writes for comparison — keys ordered, no incidental whitespace, numbers in one spelling. crate::canonical::canonicalise is what puts a value into the form this then renders; rendering an uncanonicalised value is still defined and still comparable, which is what crate::decode() needs to order a map’s entries.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Source for Value

Source§

fn kind(&self) -> &'static str

Source§

fn is_null(&self) -> bool

Source§

fn is_object(&self) -> bool

Source§

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

Source§

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

Source§

fn as_float(&self) -> Option<f64>

Source§

fn as_items(&self) -> Option<&[Self]>

Source§

fn field(&self, name: &str) -> Option<&Self>

Source§

fn entries(&self) -> Vec<(&str, &Self)>

Source§

fn as_integer(&self, path: &str) -> Result<i128, ProbeError>

Source§

fn as_float128(&self, path: &str) -> Result<Float128, ProbeError>

Source§

fn render(&self) -> String

Implementors§