pub trait Object: Any + ToAny + OpaqueClone + RawPointer + LockImmutable {
Show 13 methods
fn technetium_type_name(&self) -> String;
fn technetium_clone(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef> { ... }
fn technetium_hash(&self) -> Option<u64> { ... }
fn to_string(&self) -> RuntimeResult<String> { ... }
fn get_attr(
&self,
_attr: String,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef> { ... }
fn set_attr(
&self,
_attr: String,
_val: ObjectRef,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<()> { ... }
fn call_method(
&self,
method: &str,
_args: &[ObjectRef],
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef> { ... }
fn call(
&self,
_args: &[ObjectRef],
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef> { ... }
fn make_iter(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef> { ... }
fn take_iter(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<Option<ObjectRef>> { ... }
fn truthy(&self) -> bool { ... }
fn technetium_eq(&self, _other: ObjectRef) -> Option<bool> { ... }
fn ref_eq(&self, other: ObjectRef) -> bool { ... }
}
Expand description
The primary trait for objects in technetium.
Types that implement Object
should be of the form ObjectCell<T>
for some T. This will give all of the
requirement subtraits for free.
Required methods
fn technetium_type_name(&self) -> String
fn technetium_type_name(&self) -> String
A type name for an object.
Conventions are that type names are all lowercase, and use parentheses to denote “sub-types” (for example: “iterator(list)”)
This function should not fail, so should return a set value.
Provided methods
fn technetium_clone(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
fn technetium_clone(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
Create a deep clone of an object. This is primarily used in the clone
function in technetium
fn technetium_hash(&self) -> Option<u64>
fn technetium_hash(&self) -> Option<u64>
Hash an object. This is not required, so the default implementation always
returns None
.
In implementing a hash, it’s important that x == y
implies that x.technetium_hash() == y.technetium_hash()
to avoid logic
errors.
Note that ObjectRef does not implement Hash
in Rust, but HashableObjectRef
does. See the docs for HashableObjectRef for
more information
fn to_string(&self) -> RuntimeResult<String>
fn to_string(&self) -> RuntimeResult<String>
Convert an object to a String.
fn get_attr(
&self,
_attr: String,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
fn get_attr(
&self,
_attr: String,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
Get an attribute of an object
fn set_attr(
&self,
_attr: String,
_val: ObjectRef,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<()>
fn set_attr(
&self,
_attr: String,
_val: ObjectRef,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<()>
Set an attribute of an object
fn call_method(
&self,
method: &str,
_args: &[ObjectRef],
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
fn call_method(
&self,
method: &str,
_args: &[ObjectRef],
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
Call a given method of an object
fn call(
&self,
_args: &[ObjectRef],
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
fn call(
&self,
_args: &[ObjectRef],
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
Call a given object as a function.
fn make_iter(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
fn make_iter(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<ObjectRef>
Create an iterator over an object. This is used for initializing
for
loops.
fn take_iter(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<Option<ObjectRef>>
fn take_iter(
&self,
_context: &mut RuntimeContext<'_>
) -> RuntimeResult<Option<ObjectRef>>
Take from this object, assuming it is an iterator. This is used for
stepping through for
loops.
Determine whether an object is “truthy” (whether it should be treated as true when used as a boolean)
fn technetium_eq(&self, _other: ObjectRef) -> Option<bool>
fn technetium_eq(&self, _other: ObjectRef) -> Option<bool>
Equal-as-value (like == in Python, or .equals() in Java)
Should return None if self
cannot reasonably determine if other
is equal or not.
Typical implementations will usually only return Some(value) if they can definitively answer,
And will quickly answer None otherwise.
This allows equality to be reflexive by calling other.technetium_eq
in case the answer is None.