Trait HumusQuerySettings

Source
pub trait HumusQuerySettings<F>: Clone
where F: HumusFormat,
{ // Required method fn get_format(&self) -> F; // Provided method fn initalize_template_context(&self, _context: &mut Context) { ... } }
Available on crate feature axum-view only.
Expand description

Provides context from the query for use in the HumusEngine.

Its main job is the provide the requested HumusFormat so that the Engine knows which output to produce.

Example implementation:

use lib_humus::HumusQuerySettings;
use lib_humus::HtmlTextJsonFormat;

// Reuse the HtmlTextJsonFormat for now.
pub type ExampleResponseFormat = HtmlTextJsonFormat;
 
#[derive(Clone)]
pub struct ExampleQuerySettings {
	pub response_format: ExampleResponseFormat,
}
 
impl HumusQuerySettings<ExampleResponseFormat> for ExampleQuerySettings {
	fn get_format(&self) -> ExampleResponseFormat {
		return self.response_format.clone();
	}
}

Required Methods§

Source

fn get_format(&self) -> F

Returns the requested output format.

Provided Methods§

Source

fn initalize_template_context(&self, _context: &mut Context)

Called before rendering a template to initalize it with values that come from the query itself.

📖 Remember to document which values you set here in a place someone who wants to do something with templating is able to find it.

The default implementation does nothing.

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§