Skip to main content

Data

Struct Data 

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

The Data struct is used to represent the raw execution result of a node in a template. Data can currently be in one of three states:

  • Empty: The execution was successful but there was no result associated. For example, value assignments (x = y)
  • Success: The document data can be safely retrieved
  • Failure: An error occurred executing this node

Implementations§

Source§

impl<'a> Data

Source

pub fn empty() -> Data

Create a new empty result

Source

pub fn new<T: Into<InnerData>>(inner: T) -> Self

Create new data value

Source

pub fn inner_data(&self) -> &InnerData

Get reference to the inner value

Source

pub fn inner_data_mut(&mut self) -> &mut InnerData

Get reference to the inner value

Source

pub fn into_inner(self) -> InnerData

Get reference to the inner value

Source

pub fn render(self) -> Result<String>

Render this result

If the data is empty, an empty string is returned. If this data is in an error state, the error is returned Otherwise, the rendered string is returned

Source

pub fn is_failed(&self) -> bool

Check if this data struct has a failure

Source

pub fn is_empty(&self) -> bool

Check if this data struct is empty

Source

pub fn unwrap(self) -> Self

Unwrap the data contents

§PANIC!

This will panic if this data struct is empty or contains an error

Source

pub fn unwrap_err(self) -> TemplarError

Unwrap the data error

§PANIC!

This will panic if this data struct is empty or does not contain an error

Source

pub fn into_result(self) -> Result<Self>

Convert the data into a Result. In the case of empty data, an empty string is returned.

Source

pub fn clone_result(&self) -> Result<Self>

Clone this data into a new Result

Source

pub fn to_result(&'a self) -> Result<&'a InnerData>

Retrieve a result with a reference to the underlying document

Source

pub fn from_result(result: Result<InnerData>) -> Data

Methods from Deref<Target = InnerData>§

Source

pub fn is<T>(&self) -> bool
where T: DocumentConvertible<Q>,

Source

pub fn get_path(&self, path: &[&Unstructured<T>]) -> &Unstructured<T>
where Unstructured<T>: Index<T>,

Source

pub fn set_path<U>(&mut self, val: U, path: &[&Unstructured<T>])
where U: Into<Unstructured<T>>, Unstructured<T>: Index<T>,

Source

pub fn set<U>(&mut self, val: U)
where U: Into<Unstructured<T>>,

Source

pub fn replace<U>(&mut self, new_val: U) -> Unstructured<T>
where U: Into<Unstructured<T>>,

Source

pub fn take(&mut self) -> Unstructured<T>

Source

pub fn is_null(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_signed(&self) -> bool

Returns true if the value is any signed integer (i8, i16, i32, i64)

Source

pub fn is_unsigned(&self) -> bool

Returns true if the value is any unsigned integer (u8, u16, u32, u64)

Source

pub fn is_float(&self) -> bool

Returns true if the value is any float (f32, f64)

Source

pub fn as_usize(&self) -> Option<usize>

Source

pub fn merge(&mut self, other: Unstructured<T>)

Merge another document into this one, consuming both documents into the result. If this document is not a map or seq, it will be overwritten. If this document is a seq and the other is also a seq, the other seq will be appended to the end of this one. If the other document is not a seq, then it will be appended to the end of the sequence in this one. If this document is a map and the other document is also be a map, merging maps will cause values from the other document to overwrite this one. Otherwise, the value from the other document will overwrite this one.

Trait Implementations§

Source§

impl Clone for Data

Source§

fn clone(&self) -> Data

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Data

Source§

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

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

impl DerefMut for Data

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Display for Data

Source§

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

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

impl<T: Into<InnerData>> From<T> for Data

Source§

fn from(doc: T) -> Self

Converts to this type from the input type.
Source§

impl From<TemplarError> for Data

Source§

fn from(error: TemplarError) -> Self

Converts to this type from the input type.
Source§

impl UnstructuredDataTrait for Data

Source§

impl Deref for Data

Source§

type Target = Unstructured<Data>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Data

§

impl !RefUnwindSafe for Data

§

impl Send for Data

§

impl Sync for Data

§

impl Unpin for Data

§

impl UnsafeUnpin for Data

§

impl !UnwindSafe for Data

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.