Struct perseus::turbine::Turbine

source ·
pub struct Turbine<M: MutableStore, T: TranslationsManager> {
    pub static_dir: PathBuf,
    pub static_aliases: HashMap<String, String>,
    /* private fields */
}
Expand description

The Perseus state generator.

Fields§

§static_dir: PathBuf

This is stored as a PathBuf so we can easily check whether or not it exists.

§static_aliases: HashMap<String, String>

The app’s static aliases.

Implementations§

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub async fn build(&mut self) -> Result<(), Arc<Error>>

Builds your whole app for being run on a server. Do not use this function if you want to export your app.

This returns an Arc<Error>, since any errors are passed to plugin actions for further processing.

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub async fn export(&mut self) -> Result<(), Arc<Error>>

Exports your app to a series of static files. If any templates/capsules in your app use request-time-only functionality, this will fail.

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub async fn export_error_page( &self, code: u16, output: &str ) -> Result<(), Arc<Error>>

Exports the error page of the given exit code to the given path.

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub async fn get_state_for_path( &self, path: PathWithoutLocale, locale: String, entity_name: &str, was_incremental: bool, req: Request ) -> Result<PageDataPartial, ServerError>

Gets the state for the given path. This will render the head, but it will not render the contents, and, as a result, will not engage with any dependencies this page/widget may have. If this is used to get the state of a capsule, the head will of course be empty.

This assumes the given locale is actually supported.

source

pub async fn get_initial_load_for_path( &self, path: PathWithoutLocale, translator: &Translator, template: &Entity<SsrNode>, was_incremental: bool, req: Request ) -> Result<(PageData, TemplateState), ServerError>

Gets the full page data for the given path. This will generate the state, render the head, and render the content of the page, resolving all widget dependencies.

This takes a translator to allow the caller to derive it in a way that respects the likely need to know the translations string as well, for error page interpolation.

Like .get_state_for_path(), this returns the page data and the global state in a tuple.

Pitfalls

This currently uses a layer-based dependency resolution algorithm, as a widget may itself have widgets. However, the widgets a page/widget uses may be dependent on its state, and therefore we cannot enumerate the entire dependency tree without knowing all the states involved. Therefore, we go layer-by-layer. Currently, we wait for each layer to be fully complete before proceeding to the next one, which leads to a layer taking as long as the longest state generation within it. This can lead to poor render times when widgets are highly nested, a pattern that should be avoided as much as possible.

In future, this will build with maximal parallelism by not waiting for each layer to be finished building before proceeding to the next one.

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub async fn get_translations(&self, locale: &str) -> ApiResponse

The endpoint for getting translations.

Translations have the text/plain MIME type, as they may be in an entirely arbitrary format, which should be manually parsed.

source

pub async fn get_subsequent_load( &self, raw_path: PathWithoutLocale, locale: String, entity_name: String, was_incremental_match: bool, req: Request ) -> ApiResponse

The endpoint for getting page/capsule data through the subsequent load system.

The path provided to this may have trailing slashes, these will be handled. It is expected to end in .json (needed for compatibility with the exporting system).

Subsequent loads have the MIME type application/json.

source

pub async fn get_initial_load( &self, raw_path: PathMaybeWithLocale, req: Request ) -> ApiResponse

The endpoint for getting the full HTML contents of a page with no round trips (except for suspended states and/or delayed widgets). This is what should be returned to the user when they first ask for a page in the app.

This expects to take a raw path without the locale split out that still needs URL decoding.

If there’s an error anywhere in this function, it will return the HTML of a proper error page.

Initial loads always (even in the case of errors) have the MIME type text/html.

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub fn tinker(&self) -> Result<(), PluginError>

Runs tinker plugin actions.

source§

impl<M: MutableStore, T: TranslationsManager> Turbine<M, T>

source

pub async fn populate_after_build(&mut self) -> Result<(), ServerError>

Updates some internal fields of the turbine by assuming the app has been built in the past. This expects a number of things to exist in the filesystem. Note that calling .build() will automatically perform this population.

Trait Implementations§

source§

impl<M: Debug + MutableStore, T: Debug + TranslationsManager> Debug for Turbine<M, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<M: MutableStore, T: TranslationsManager> TryFrom<PerseusAppBase<SsrNode, M, T>> for Turbine<M, T>

§

type Error = PluginError

The type returned in the event of a conversion error.
source§

fn try_from(app: PerseusAppBase<SsrNode, M, T>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<M, T> !RefUnwindSafe for Turbine<M, T>

§

impl<M, T> Send for Turbine<M, T>

§

impl<M, T> Sync for Turbine<M, T>

§

impl<M, T> Unpin for Turbine<M, T>where M: Unpin, T: Unpin,

§

impl<M, T> !UnwindSafe for Turbine<M, T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.