Trait oso::ToPolar

source ·
pub trait ToPolar {
    // Required method
    fn to_polar(self) -> PolarValue;
}
Expand description

Convert Rust types to Polar types.

This trait is automatically implemented for any type that implements the PolarClass marker trait, which should be preferred. You can use the PolarClass derive macro to derive that trait.

For non-primitive types, the instance will be stored on the provided Host.

Trait bounds

The default implementation for PolarClass requires types to be Send and Sync, since it is possible to store a ToPolar value on an Oso instance which can be shared between threads.

ToPolar implementors must also be concrete, sized types without any borrows.

Examples

Convert a primitive type into a polar value:

use oso::{PolarValue, ToPolar};

let string = "This is a string";
let value = string.to_polar();

assert_eq!(value, PolarValue::String(string.into()));

Convert a custom type into a polar value:

use oso::{PolarValue, PolarClass, ToPolar};

#[derive(PolarClass)]
struct MyClass;

let class = MyClass;
let value = class.to_polar();

assert!(matches!(value, PolarValue::Instance(_)));

Required Methods§

source

fn to_polar(self) -> PolarValue

Convert this value into a Polar value.

Implementations on Foreign Types§

source§

impl ToPolar for bool

source§

impl ToPolar for f32

source§

impl ToPolar for f64

source§

impl ToPolar for i8

source§

impl ToPolar for i16

source§

impl ToPolar for i32

source§

impl ToPolar for i64

source§

impl ToPolar for u8

source§

impl ToPolar for u16

source§

impl ToPolar for u32

source§

impl ToPolar for String

source§

impl<'a> ToPolar for &'a str

source§

impl<'a, T: Clone + ToPolar> ToPolar for &'a [T]

source§

impl<T: ToPolar> ToPolar for Option<T>

source§

impl<T: ToPolar> ToPolar for BinaryHeap<T>

source§

impl<T: ToPolar> ToPolar for BTreeMap<&str, T>

source§

impl<T: ToPolar> ToPolar for BTreeMap<String, T>

source§

impl<T: ToPolar> ToPolar for BTreeSet<T>

source§

impl<T: ToPolar> ToPolar for LinkedList<T>

source§

impl<T: ToPolar> ToPolar for VecDeque<T>

source§

impl<T: ToPolar> ToPolar for Vec<T>

source§

impl<T: ToPolar> ToPolar for HashMap<&str, T>

source§

impl<T: ToPolar> ToPolar for HashMap<String, T>

source§

impl<T: ToPolar> ToPolar for HashSet<T>

Implementors§