Struct mica_hl::TypeBuilder
source · [−]pub struct TypeBuilder<T>where
T: ?Sized,{ /* private fields */ }
Expand description
A builder that allows for binding APIs with user-defined types.
Implementations
sourceimpl<T> TypeBuilder<T>where
T: ?Sized,
impl<T> TypeBuilder<T>where
T: ?Sized,
sourcepub fn add_raw_function(
self,
name: &str,
parameter_count: Option<u16>,
f: FunctionKind
) -> Self
pub fn add_raw_function(
self,
name: &str,
parameter_count: Option<u16>,
f: FunctionKind
) -> Self
Adds a raw instance function to the type.
You should generally prefer add_function
instead of this.
parameter_count
should reflect the parameter count of the function. Pass None
if the
function accepts a variable number of arguments. Note that unlike with bare raw functions
there can be two functions with the same name defined on a type, as long as they have
different arities. Functions with specific arities take priority over varargs.
Note that this function consumes the builder; this is because calls to functions that add into the type are meant to be chained together in one expression.
sourcepub fn add_raw_static(
self,
name: &str,
parameter_count: Option<u16>,
f: FunctionKind
) -> Self
pub fn add_raw_static(
self,
name: &str,
parameter_count: Option<u16>,
f: FunctionKind
) -> Self
Adds a raw static function to the type.
You should generally prefer add_static
instead of this.
parameter_count
should reflect the parameter count of the function. Pass None
if the
function accepts a variable number of arguments. Note that unlike with bare raw functions
there can be two functions with the same name defined on a type, as long as they have
different arities. Functions with specific arities take priority over varargs.
Note that this function consumes the builder; this is because calls to functions that add into the type are meant to be chained together in one expression.
sourcepub fn add_raw_constructor(
self,
name: &str,
parameter_count: Option<u16>,
f: Box<dyn FnOnce(Rc<dyn ObjectConstructor<T>>) -> RawForeignFunction>
) -> Self
pub fn add_raw_constructor(
self,
name: &str,
parameter_count: Option<u16>,
f: Box<dyn FnOnce(Rc<dyn ObjectConstructor<T>>) -> RawForeignFunction>
) -> Self
Adds a raw constructor to the type.
You should generally prefer add_constructor
instead of this.
parameter_count
should reflect the parameter count of the function. Pass None
if the
function accepts a variable number of arguments. Note that unlike with bare raw functions
there can be two functions with the same name defined on a type, as long as they have
different arities. Functions with specific arities take priority over varargs.
Note that this function consumes the builder; this is because calls to functions that add into the type are meant to be chained together in one expression.
sourcepub fn add_function<F, V>(self, name: &str, f: F) -> Selfwhere
V: Method<T>,
F: ForeignFunction<V>,
pub fn add_function<F, V>(self, name: &str, f: F) -> Selfwhere
V: Method<T>,
F: ForeignFunction<V>,
Adds an instance function to the struct.
The function must follow the “method” calling convention, in that it accepts &T
or
&mut T
as its first parameter.
sourcepub fn add_builtin_trait_function<S, B, F>(self, which: B, f: F) -> Selfwhere
B: BuiltinTraitFunction<S>,
F: ForeignFunction<S>,
pub fn add_builtin_trait_function<S, B, F>(self, which: B, f: F) -> Selfwhere
B: BuiltinTraitFunction<S>,
F: ForeignFunction<S>,
Adds a function that’s part of a built-in trait implementation.
The function must have a signature that’s compatible with the built-in trait in question.
sourcepub fn add_static<F, V>(self, name: &str, f: F) -> Selfwhere
V: Bare,
F: ForeignFunction<V>,
pub fn add_static<F, V>(self, name: &str, f: F) -> Selfwhere
V: Bare,
F: ForeignFunction<V>,
Adds a static function to the struct.
The function must follow the “bare” calling convention, in that it doesn’t accept a reference
to T
as its first parameter.
sourcepub fn add_constructor<F, G, V>(self, name: &str, f: F) -> Selfwhere
V: Bare,
F: FnOnce(Rc<dyn ObjectConstructor<T>>) -> G,
F: 'static,
G: ForeignFunction<V>,
pub fn add_constructor<F, G, V>(self, name: &str, f: F) -> Selfwhere
V: Bare,
F: FnOnce(Rc<dyn ObjectConstructor<T>>) -> G,
F: 'static,
G: ForeignFunction<V>,
Adds a constructor to the type.
A constructor is a static function responsible for creating instances of a type. The function passed to this one must return another function that actually constructs the object.
Constructors use the “bare” calling convention, in that they don’t accept a self
parameter.