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§
Provided Methods§
Sourcefn as_string(&self) -> String
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
Sourcefn get_field(&self, _field: Rc<dyn Object>) -> Rc<dyn Object>
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.
Sourcefn set_field(&mut self, _field: Rc<dyn Object>, _value: Rc<dyn Object>)
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.