Skip to main content

FromWorld

Trait FromWorld 

Source
pub trait FromWorld {
    // Required method
    fn from_world(world: &mut World) -> Self;
}
Expand description

Creates an instance of the type this trait is implemented for using data from the supplied World.

This can be helpful for complex initialization or context-aware defaults.

FromWorld is automatically implemented for any type implementing Default and may also be derived for:

  • any struct whose fields all implement FromWorld
  • any enum where one variant has the attribute #[from_world]

#[derive(Default)]
struct A;

#[derive(Default)]
struct B(Option<u32>)

struct C;

impl FromWorld for C {
    fn from_world(_world: &mut World) -> Self {
        Self
    }
}

#[derive(FromWorld)]
struct D(A, B, C);

#[derive(FromWorld)]
enum E {
    #[from_world]
    F,
    G
}

Required Methods§

Source

fn from_world(world: &mut World) -> Self

Creates Self using data from the given World.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§