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

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.

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.

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.

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.

Adds an ivar with type T and the provided name.

Panics

If the ivar wasn’t successfully added.

Adds the given protocol to self.

Panics

If the protocol wasn’t successfully added.

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

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.