Trait Class

Source
pub trait Class: Object + Default {
    type Super: Class + Into<Self>;

    // Provided methods
    fn __new__() -> Self { ... }
    fn __init__<A>(&mut self, args: A) { ... }
}
Expand description

The Class trait is used to define Python classes. Classes are Object factories, meaning they create instances of objects.

Required Associated Types§

Source

type Super: Class + Into<Self>

Provided Methods§

Source

fn __new__() -> Self

Returns the method resolution order of the class. new returns an instance of the class. Because of Rust’s requirement that all objects be initialized, we require that the Object implement the Default trait. By default, we just return the default instance of the object.

Source

fn __init__<A>(&mut self, args: A)

init is called after new and is used to initialize the object.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§