pub trait AsValue {
    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

Returns the implemented type as a Value

Example
use tau_engine::AsValue;

let value = "foobar".as_value();

Implementations on Foreign Types

Implementors