pub trait Renderable: Serialize + GetPath {
// Required method
fn get_template() -> &'static str;
// Provided method
fn render(
&self,
path: &Path,
game_state: &GameState,
grapher: Option<&Grapher>,
data: &GameData,
) { ... }
}
Expand description
Trait for objects that can be rendered into a html page. Since this uses [minijinja] the serde::Serialize trait is also needed. Each object that implements this trait should have a corresponding template file in the templates folder.
Required Methods§
Sourcefn get_template() -> &'static str
fn get_template() -> &'static str
Returns the template file name. This method is used to retrieve the template from the [Environment] object in the Renderer object.
Provided Methods§
Sourcefn render(
&self,
path: &Path,
game_state: &GameState,
grapher: Option<&Grapher>,
data: &GameData,
)
fn render( &self, path: &Path, game_state: &GameState, grapher: Option<&Grapher>, data: &GameData, )
Renders all the objects that are related to this object. For example: graphs, maps, etc. This is where your custom rendering logic should go.
§Arguments
path
- The root output path of the renderer.game_state
- The game state object.grapher
- The grapher object, if it exists.data
- The game data object.
§Default Implementation
The default implementation does nothing. It is up to the implementing object to override this method.
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.