Trait Object

Source
pub trait Object:
    Display
    + Debug
    + ObjectFromStr
    + ObjectPartialEq
    + ObjectPartialOrd
    + ObjectEq
    + ObjectOrd {
    // Required methods
    fn class(&self) -> Class;
    fn as_number(&self) -> f64;
    fn as_bool(&self) -> bool;

    // Provided methods
    fn as_string(&self) -> String { ... }
    fn get_field(&self, _field: Rc<dyn Object>) -> Rc<dyn Object> { ... }
    fn set_field(&mut self, _field: Rc<dyn Object>, _value: Rc<dyn Object>) { ... }
    fn cast_to(&self, to: &Class) -> Rc<dyn Object> { ... }
}
Expand description

The object of a data type. Data type is derived from the object’s class. Methods specified here are for use in nodes mostly.

Required Methods§

Source

fn class(&self) -> Class

Source

fn as_number(&self) -> f64

Convert to number

Source

fn as_bool(&self) -> bool

Convert to boolean

Provided Methods§

Source

fn as_string(&self) -> String

Since Object requires Display, this has little use and is implemented through ToString, which is implemented for all types implementing Display. Left for consistency with as_number and other methods

Source

fn get_field(&self, _field: Rc<dyn Object>) -> Rc<dyn Object>

Suggested implementation: Have a HashMap<String, Rc<dyn Object>> to manage fields. Default implementation is unimplemented!() because most types don’t have fields.

Source

fn set_field(&mut self, _field: Rc<dyn Object>, _value: Rc<dyn Object>)

Suggested implementation: use String::from to convert &str to String and use that as insertion key. Default implementation is unimplemented!() because most types don’t have fields.

Source

fn cast_to(&self, to: &Class) -> Rc<dyn Object>

Implementations on Foreign Types§

Source§

impl Object for bool

Source§

fn class(&self) -> Class

Source§

fn as_number(&self) -> f64

Source§

fn as_bool(&self) -> bool

Source§

impl Object for f64

Source§

fn class(&self) -> Class

Source§

fn as_number(&self) -> f64

Source§

fn as_bool(&self) -> bool

Source§

fn get_field(&self, field: Rc<dyn Object>) -> Rc<dyn Object>

Source§

impl Object for String

Source§

fn class(&self) -> Class

Source§

fn as_number(&self) -> f64

Source§

fn as_bool(&self) -> bool

Implementors§