Trait Prototypical

Source
pub trait Prototypical: Asset + Sized {
    type Id: Clone + Debug + Eq + Hash + Send + Sync + ToString;
    type Child: PrototypicalChild<Self>;

    // Required methods
    fn id(&self) -> &Self::Id;
    fn path(&self) -> &ProtoPath;
    fn schematics(&self) -> &Schematics;
    fn schematics_mut(&mut self) -> &mut Schematics;
    fn templates(&self) -> Option<&Templates>;
    fn templates_mut(&mut self) -> Option<&mut Templates>;
    fn dependencies(&self) -> &Dependencies;
    fn dependencies_mut(&mut self) -> &mut Dependencies;
    fn children(&self) -> Option<&Children<Self>>;
    fn children_mut(&mut self) -> Option<&mut Children<Self>>;

    // Provided method
    fn requires_entity(&self) -> bool { ... }
}
Expand description

The trait used to define a prototype.

Prototypes are containers for Schematics that can be spawned in at runtime. They may also inherit from other prototypes (where the inherited prototypes are known as Templates) and contain a hierarchy of Children.

Required Associated Types§

Source

type Id: Clone + Debug + Eq + Hash + Send + Sync + ToString

The type used to identify this prototype.

This can be used to control how a prototype is accessed. For example, if we wanted to split prototypes into “packages”, then we could require a package identifier along with the prototype name in order to access the prototype:

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct MyProtoId {
  package: String,
  name: String,
}

impl Display for MyProtoId {
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    write!(f, "{}::{}", self.package, self.name)
  }
}
Source

type Child: PrototypicalChild<Self>

The type of the child this prototype uses.

This is used to configure how a child is processed.

Required Methods§

Source

fn id(&self) -> &Self::Id

The ID of this prototype.

Source

fn path(&self) -> &ProtoPath

The path to this prototype’s asset file.

Source

fn schematics(&self) -> &Schematics

An immutable reference to the collection of Schematics contained in this prototype.

Source

fn schematics_mut(&mut self) -> &mut Schematics

A mutable reference to the collection of Schematics contained in this prototype.

Source

fn templates(&self) -> Option<&Templates>

An immutable reference to the collection of Templates inherited by this prototype, if any.

Source

fn templates_mut(&mut self) -> Option<&mut Templates>

A mutable reference to the collection of Templates inherited by this prototype, if any.

Source

fn dependencies(&self) -> &Dependencies

An immutable reference to the collection of Dependencies used by this prototype.

Source

fn dependencies_mut(&mut self) -> &mut Dependencies

A mutable reference to the collection of Dependencies used by this prototype.

Source

fn children(&self) -> Option<&Children<Self>>

An immutable reference to the collection of Children contained in this prototype, if any.

Source

fn children_mut(&mut self) -> Option<&mut Children<Self>>

A mutable reference to the collection of Children contained in this prototype, if any.

Provided Methods§

Source

fn requires_entity(&self) -> bool

Whether or not this prototype requires an entity to be spawned.

Defaults to true.

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§