[−][src]Struct oso::Class
Fields
name: String
The class name. Defaults to the std::any::type_name
constructor: Option<Constructor>
A wrapped method that constructs an instance of T
from Polar terms
attributes: HashMap<Symbol, InstanceMethod>
Methods that return simple attribute lookups on an instance of T
instance_methods: HashMap<Symbol, InstanceMethod>
Instance methods on T
that expect Polar terms, and an instance of &T
class_methods: HashMap<Symbol, ClassMethod>
Class methods on T
type_id: TypeId
Implementations
impl<T> Class<T> where
T: 'static,
[src]
T: 'static,
pub fn new() -> Self
[src]
Create a new class builder.
pub fn with_default() -> Self where
T: Default,
[src]
T: Default,
Create a new class builder for a type that implements Default and use that as the constructor.
pub fn with_constructor<F, Args>(f: F) -> Self where
F: Function<Args, Result = T> + 'static,
Args: FromPolar + 'static,
[src]
F: Function<Args, Result = T> + 'static,
Args: FromPolar + 'static,
Create a new class builder with a given constructor.
pub fn set_constructor<F, Args>(self, f: F) -> Self where
F: Function<Args, Result = T> + 'static,
Args: FromPolar + 'static,
[src]
F: Function<Args, Result = T> + 'static,
Args: FromPolar + 'static,
Set the constructor function to use for polar new
statements.
pub fn set_equality_check<F>(self, f: F) -> Self where
F: Fn(&T, &T) -> bool + Send + Sync + 'static,
[src]
F: Fn(&T, &T) -> bool + Send + Sync + 'static,
Set an equality function to be used for polar ==
statements.
pub fn with_equality_check(self) -> Self where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
Use PartialEq::eq as the equality check for polar ==
statements.
pub fn add_attribute_getter<F, R>(self, name: &str, f: F) -> Self where
F: Method<T, Result = R> + 'static,
R: ToPolarResults + 'static,
T: 'static,
[src]
F: Method<T, Result = R> + 'static,
R: ToPolarResults + 'static,
T: 'static,
Add an attribute getter for statments like foo.bar
`class.add_attribute_getter("bar", |instance| instance.bar)
pub fn name(self, name: &str) -> Self
[src]
Set the name of the polar class.
pub fn add_method<F, Args, R>(self, name: &str, f: F) -> Self where
Args: FromPolar,
F: Method<T, Args, Result = R> + 'static,
R: ToPolarResults + 'static,
[src]
Args: FromPolar,
F: Method<T, Args, Result = R> + 'static,
R: ToPolarResults + 'static,
Add a method for polar method calls like foo.plus(1)
class.add_attribute_getter("bar", |instance, n| instance.foo + n)
pub fn add_iterator_method<F, Args, I>(self, name: &str, f: F) -> Self where
Args: FromPolar,
F: Method<T, Args> + 'static,
F::Result: IntoIterator<Item = I>,
<<F as Method<T, Args>>::Result as IntoIterator>::IntoIter: Sized + Clone + 'static,
I: ToPolarResults + 'static,
T: 'static,
[src]
Args: FromPolar,
F: Method<T, Args> + 'static,
F::Result: IntoIterator<Item = I>,
<<F as Method<T, Args>>::Result as IntoIterator>::IntoIter: Sized + Clone + 'static,
I: ToPolarResults + 'static,
T: 'static,
A method that returns multiple values. Every element in the iterator returned by the method will be a separate polar return value.
pub fn add_class_method<F, Args, R>(self, name: &str, f: F) -> Self where
F: Function<Args, Result = R> + 'static,
Args: FromPolar + 'static,
R: ToPolarResults + 'static,
[src]
F: Function<Args, Result = R> + 'static,
Args: FromPolar + 'static,
R: ToPolarResults + 'static,
A method that's called on the type instead of an instance.
eg Foo.pi
pub fn erase_type(self) -> Class<()>
[src]
Erase the generic type parameter This is done before registering so that the host can store all of the same type. The generic paramtere is just used for the builder pattern part of Class TODO: Skip this shenanigans and make there a builder instead?
pub fn build(self) -> Class<()>
[src]
pub fn is_class<C: 'static>(&self) -> bool
[src]
pub fn is_instance(&self, instance: &Instance) -> bool
[src]
pub fn equals(&self, instance: &Instance, other: &Instance) -> Result<bool>
[src]
impl Class
[src]
pub fn cast_to_instance(&self, instance: impl Any) -> Instance
[src]
pub fn init(&self, fields: Vec<Term>, host: &mut Host) -> Result<Instance>
[src]
Trait Implementations
impl<T: Clone> Clone for Class<T>
[src]
impl Debug for Class
[src]
impl Default for Class
[src]
impl ToPolar for Class
[src]
Auto Trait Implementations
impl<T = ()> !RefUnwindSafe for Class<T>
impl<T> Send for Class<T> where
T: Send,
T: Send,
impl<T> Sync for Class<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Class<T> where
T: Unpin,
T: Unpin,
impl<T = ()> !UnwindSafe for Class<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,