Struct objc2::declare::ClassBuilder

source ·
pub struct ClassBuilder { /* private fields */ }
Expand description

A type for declaring a new class and adding new methods and ivars to it before registering it.

Implementations§

source§

impl ClassBuilder

source

pub fn new(name: &str, superclass: &Class) -> Option<Self>

Constructs a ClassBuilder with the given name and superclass.

Returns None if the class couldn’t be allocated, or a class with that name already exist.

source

pub fn root<F>(name: &str, intitialize_fn: F) -> Option<Self>where F: MethodImplementation<Callee = Class, Args = (), Ret = ()>,

Constructs a ClassBuilder declaring a new root class with the given name.

Returns None if the class couldn’t be allocated.

An implementation for +initialize must also be given; the runtime calls this method for all classes, so it must be defined on root classes.

Note that implementing a root class is not a simple endeavor! For example, your class probably cannot be passed to Cocoa code unless the entire NSObject protocol is implemented. Functionality it expects, like implementations of -retain and -release used by ARC, will not be present otherwise.

source

pub unsafe fn add_method<T, F>(&mut self, sel: Sel, func: F)where T: Message + ?Sized, F: MethodImplementation<Callee = T>,

Adds a method with the given name and implementation.

Panics

Panics if the method wasn’t sucessfully added or if the selector and function take different numbers of arguments.

Safety

The caller must ensure that the types match those that are expected when the method is invoked from Objective-C.

source

pub unsafe fn add_class_method<F>(&mut self, sel: Sel, func: F)where F: MethodImplementation<Callee = Class>,

Adds a class method with the given name and implementation.

Panics

Panics if the method wasn’t sucessfully added or if the selector and function take different numbers of arguments.

Safety

The caller must ensure that the types match those that are expected when the method is invoked from Objective-C.

source

pub fn add_ivar<T: Encode>(&mut self, name: &str)

Adds an ivar with type T and the provided name.

Panics

If the ivar wasn’t successfully added for some reason - this usually happens if there already was an ivar with that name.

source

pub fn add_static_ivar<T: IvarType>(&mut self)

Adds an instance variable from an IvarType.

Panics

Same as ClassBuilder::add_ivar.

source

pub fn add_protocol(&mut self, proto: &Protocol)

Adds the given protocol to self.

Panics

If the protocol wasn’t successfully added.

source

pub fn register(self) -> &'static Class

Registers the ClassBuilder, consuming it, and returns a reference to the newly registered Class.

Trait Implementations§

source§

impl Debug for ClassBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for ClassBuilder

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for ClassBuilder

source§

impl Sync for ClassBuilder

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> AutoreleaseSafe for Twhere T: ?Sized,