pub struct HumusEngine<ApiFormat>where
ApiFormat: HumusApiFormat,{
pub templating_engine: TemplatingEngine<ApiFormat>,
pub language_engine: Arc<LanguageEngine>,
/* private fields */
}Expand description
🌱 An all in one datatype that takes care of frontend rendering.
You should construct one using a crate::HumusEngineLoader unless you have a very good reason not to.
The ApiFormat type defines which API responses your implementation can produce.
For a good default you can use JsonOnlyApiFormat.
Note: The private field is a PhantomData because the engine only works
correctly when ApiFormat stays the same throuout its life, but
it doesn’t have to store one of those.
The HumusEngine itself is a container for the TemplatingEngine which takes care of rendering text templates and API responses and the LanguageEngine which can be used by the TemplateEngine and your code to provide localized results.
Your main point of interaction will be the render_view function which you can use after fetching all the data your frontend needs to tun the data into an HTTP response.
Fields§
§templating_engine: TemplatingEngine<ApiFormat>The templating engine responsible for rendering text templates
language_engine: Arc<LanguageEngine>The language engine that is responsible for localizing this template
Implementations§
Source§impl<ApiFormat> HumusEngine<ApiFormat>where
ApiFormat: HumusApiFormat,
impl<ApiFormat> HumusEngine<ApiFormat>where
ApiFormat: HumusApiFormat,
Sourcepub fn new(
templating_engine: TemplatingEngine<ApiFormat>,
language_engine: Arc<LanguageEngine>,
) -> Self
pub fn new( templating_engine: TemplatingEngine<ApiFormat>, language_engine: Arc<LanguageEngine>, ) -> Self
Creates a new Templating Engine.
An alternative would be converting from a HumusProtoEngine.
Sourcepub fn render_view<S: HumusQuerySettings>(
&self,
settings: &S,
view: impl HumusView<S, ApiFormat>,
) -> Response
pub fn render_view<S: HumusQuerySettings>( &self, settings: &S, view: impl HumusView<S, ApiFormat>, ) -> Response
Takes settings and a view, converting it to a serveable response.
Example:
async fn hello_world_handler(
State(arc_state): State<Arc<ServiceSharedState>>,
Extension(settings): Extension<QuerySettings>,
) -> Response {
let state = Arc::clone(&arc_state);
state.templating_engine.render_view(
&settings,
View::Message{
title: "Hey There!".to_string(),
message: "You are an awesome creature!".to_string()
},
)
}
Sourcepub fn language_engine(&self) -> &LanguageEngine
pub fn language_engine(&self) -> &LanguageEngine
Accessor for the localization engine inside this HumusEngine
You can use this to localize text elsewhere in your code.
Sourcepub fn templates_manifest(&self) -> &TemplatesManifest
pub fn templates_manifest(&self) -> &TemplatesManifest
Accessor for the templates manifest inside this HumusEngine
Sourcepub fn list_available_formats(&self) -> HashSet<HumusFormatIdentifier>
pub fn list_available_formats(&self) -> HashSet<HumusFormatIdentifier>
Returns a HashSet of all valid format identifiers this HumusEngine can render
Sourcepub fn get_format_chooser(&self) -> FormatChooser
pub fn get_format_chooser(&self) -> FormatChooser
Returns a FormatChooser matching this HumusEngine.
Sourcepub fn get_template_settings_layer(&self) -> TemplateSettingsLayer
pub fn get_template_settings_layer(&self) -> TemplateSettingsLayer
Constructs a ready to use TemplateSettingsLayer that matches the configuration of this engine.
Trait Implementations§
Source§impl<ApiFormat> Clone for HumusEngine<ApiFormat>where
ApiFormat: HumusApiFormat + Clone,
impl<ApiFormat> Clone for HumusEngine<ApiFormat>where
ApiFormat: HumusApiFormat + Clone,
Source§fn clone(&self) -> HumusEngine<ApiFormat>
fn clone(&self) -> HumusEngine<ApiFormat>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more