Trait AsValue

Source
pub trait AsValue {
    // Required method
    fn as_value(&self) -> Value<'_>;
}
Expand description

A data type that can be represented as a Value.

§Implementations

As long as the data type can be coerced into one of the values provided by Value then AsValue can be implemented on that type. Below is a contrived example:

use std::borrow::Cow;

use tau_engine::{AsValue, Value};

enum Foo {
    Bar,
    Baz
}

impl AsValue for Foo {
    fn as_value(&self) -> Value<'_> {
        match self {
            Self::Bar => Value::String(Cow::Borrowed("bar")),
            Self::Baz => Value::String(Cow::Borrowed("baz")),
        }
    }
}

Required Methods§

Source

fn as_value(&self) -> Value<'_>

Returns the implemented type as a Value

§Example
use tau_engine::AsValue;

let value = "foobar".as_value();

Implementations on Foreign Types§

Source§

impl AsValue for Json

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for Yaml

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for bool

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for f32

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for f64

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for i8

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for i16

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for i32

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for i64

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for isize

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for str

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for u8

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for u16

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for u32

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for u64

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for ()

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for usize

Source§

fn as_value(&self) -> Value<'_>

Source§

impl AsValue for String

Source§

fn as_value(&self) -> Value<'_>

Source§

impl<V> AsValue for Option<V>
where V: AsValue,

Source§

fn as_value(&self) -> Value<'_>

Source§

impl<V> AsValue for Vec<V>
where V: AsValue,

Source§

fn as_value(&self) -> Value<'_>

Source§

impl<V> AsValue for HashSet<V>
where V: AsValue,

Source§

fn as_value(&self) -> Value<'_>

Implementors§

Source§

impl<O: Object> AsValue for O