AddDatabaseMapping

Trait AddDatabaseMapping 

Source
pub trait AddDatabaseMapping {
    // Required method
    fn add_database_mapping<T: Serialize + for<'de> Deserialize<'de> + Component>(
        &mut self,
    ) -> &mut Self;
}
Expand description

Trait to add database mapping capabilities for components

Required Methods§

Source

fn add_database_mapping<T: Serialize + for<'de> Deserialize<'de> + Component>( &mut self, ) -> &mut Self

Adds database persistence for a component type. This will automatically handle saving and loading the component to/from the database.

§Type Parameters
  • T: Component type that implements Serialize, Deserialize, and Component
§Example
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_easy_database::*;

#[derive(Component, serde::Serialize, serde::Deserialize)]
pub struct Player(pub String);

#[derive(Component, serde::Serialize, serde::Deserialize)]
pub struct Score(pub u32);

fn main() {
    App::new()
        //...
        .add_plugins(DatabasePlugin)
        // Register as many components as you need
        .add_database_mapping::<Player>()
        .add_database_mapping::<Score>()
        .run();
}

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.

Implementations on Foreign Types§

Source§

impl AddDatabaseMapping for App

Source§

fn add_database_mapping<T: Serialize + for<'de> Deserialize<'de> + Component + Any>( &mut self, ) -> &mut Self

Implementors§