Struct perseus::PerseusAppBase

source ·
pub struct PerseusAppBase<G: Html, M: MutableStore, T: TranslationsManager> { /* private fields */ }
Expand description

The options for constructing a Perseus app. This struct will tie together all your code, declaring to Perseus where your templates, error pages, static content, etc. are.

Implementations

Creates a new instance of a Perseus app using the default filesystem-based mutable store (see FsMutableStore). For most apps, this will be sufficient. Note that this initializes the translations manager as a dummy (see FsTranslationsManager), and adds no templates or error pages.

In development, you can get away with defining no error pages, but production apps (e.g. those created with perseus deploy) MUST set their own custom error pages.

This is asynchronous because it creates a translations manager in the background.

The same as .locales_and_translations_manager(), but this accepts a literal Locales struct, which means this can be used when you’re using FsTranslationsManager but when you don’t know if your app is using i18n or not (almost always middleware).

Sets the internationalization information for an app using the default translations manager (FsTranslationsManager). This handles locale caching and the like automatically for you, though you could alternatively use .locales() and .translations_manager() independently to customize various behaviors. This takes the same arguments as .locales(), so the first argument is the default locale (used as a fallback for users with no locale preferences set in their browsers), and the second is a list of other locales supported.

If you’re not using i18n, you don’t need to call this function. If you for some reason do have to though (e.g. overriding some other preferences in middleware), use .disable_i18n(), not this, as you’re very likely to shoot yourself in the foot! (If i18n is disabled, the default locale MUST be set to xx-XX, for example.)

Creates a new instance of a Perseus app, with the default options and a customizable MutableStore, using the default dummy FsTranslationsManager by default (though this can be changed).

Sets the HTML ID of the <div> element at which to insert Perseus. In your index view, this should use PerseusRoot.

Note: if you’re using string HTML, the <div> with this ID MUST look exactly like this: <div id="some-id-here"></div>, spacing and all!

Sets the location of the directory storing static assets to be hosted under the URL /.perseus/static/. By default, this is static/ at the root of your project.

Sets all the app’s templates. This takes a vector of boxed functions that return templates.

Usually, it’s preferred to run .template() once for each template, rather than manually constructing this more inconvenient type.

Adds a single new template to the app (convenience function). This takes a function that returns a template (for internal reasons).

See Template for further details.

Sets the app’s error pages. See ErrorPages for further details.

Sets the app’s GlobalStateCreator.

Sets the locales information for the app. The first argument is the default locale (used as a fallback for users with no locale preferences set in their browsers), and the second is a list of other locales supported.

Note that this does not update the translations manager, which must be done separately (if you’re using FsTranslationsManager, the default, you can use .locales_and_translations_manager() to set both at once).

If you’re not using i18n, you don’t need to call this function. If you for some reason do have to though (e.g. overriding some other preferences in middleware), use .disable_i18n(), not this, as you’re very likely to shoot yourself in the foot! (If i18n is disabled, the default locale MUST be set to xx-XX, for example.)

Sets the locales information directly based on an instance of Locales. Usually, end users will use .locales() instead for a friendlier interface.

Sets the translations manager. If you’re using the default translations manager (FsTranslationsManager), you can use .locales_and_translations_manager() to set this automatically based on the locales information. This takes a Future<Output = T>, where T is your translations manager’s type.

The reason that this takes a Future is to avoid the use of .await in your app definition code, which must be synchronous due to constraints of Perseus’ browser-side systems. When your code is run on the server, the Future will be .awaited on, but in Wasm, it will be discarded and ignored, since the translations manager isn’t needed in Wasm.

This is generally intended for use with custom translations manager or specific use-cases with the default (mostly to do with custom caching behavior).

Explicitly disables internationalization. You shouldn’t ever need to call this, as it’s the default, but you may want to if you’re writing middleware that doesn’t support i18n.

Sets all the app’s static aliases. This takes a map of URLs (e.g. /file) to resource paths, relative to the project directory (e.g. style.css). Generally, calling .static_alias() many times is preferred.

Adds a single static alias. This takes a URL path (e.g. /file) followed by a path to a resource (which must be within the project directory, e.g. style.css).

Sets the plugins that the app will use. See Plugins for further details.

Sets the MutableStore for the app to use, which you would change for some production server environments if you wanted to store build artifacts that can change at runtime in a place other than on the filesystem (created for serverless functions specifically).

Sets the ImmutableStore for the app to use. You should almost never need to change this unless you’re not working with the CLI.

Sets the index view as a string. This should be used if you’re using an index.html file or the like.

Note: if possible, you should switch to using .index_view(), which uses a Sycamore view rather than an HTML string.

Sets the index view using a Sycamore view, which avoids the need to write any HTML by hand whatsoever. Note that this must contain a <head> and <body> at a minimum.

Warning: this view can’t be reactive (yet). It will be rendered to a static string, which won’t be hydrated.

Sets the maximum number of pages that can have their states stored in the page state store before the oldest will be evicted. If your app is taking up a substantial amount of memory in the browser because your page states are fairly large, making this smaller may help.

By default, this is set to 25. Higher values may lead to memory difficulties in both development and production, and the poor user experience of a browser that’s substantially slowed down.

WARNING: any setting applied here will impact HSR in development! (E.g. setting this to 1 would mean your position would only be saved for the most recent page.)

Gets the HTML ID of the <div> at which to insert Perseus.

Gets the directory containing static assets to be hosted under the URL /.perseus/static/.

Gets the index view as a string, without generating an HTML shell (pass this into ::get_html_shell() to do that).

Note that this automatically adds <!DOCTYPE html> to the start of the HTML shell produced, which can only be overridden with a control plugin (though you should really never do this in Perseus, which targets HTML on the web).

Gets an HTML shell from an index view string. This is broken out so that it can be executed after the app has been built (which requires getting the translations manager, consuming self). As inconvenient as this is, it’s necessitated, otherwise exporting would try to access the built app before it had actually been built.

Gets the templates in an Rc-based HashMap for non-concurrent access.

Gets the templates in an Arc-based HashMap for concurrent access. This should only be relevant on the server-side.

Gets the ErrorPages used in the app. This returns an Rc.

Gets the maximum number of pages that can be stored in the page state store before the oldest are evicted.

Gets the GlobalStateCreator. This can’t be directly modified by plugins because of reactive type complexities.

Gets the locales information.

Gets the server-side TranslationsManager. Like the mutable store, this can’t be modified by plugins due to trait complexities.

This involves evaluating the future stored for the translations manager, and so this consumes self.

Gets the ImmutableStore.

Gets the MutableStore. This can’t be modified by plugins due to trait complexities, so plugins should instead expose a function that the user can use to manually set it.

Gets the plugins registered for the app. These are passed around and used in a way that doesn’t require them to be concurrently accessible, and so are provided in an Rc.

Gets the static aliases. This will check all provided resource paths to ensure they don’t reference files outside the project directory, due to potential security risks in production (we don’t want to accidentally serve an arbitrary in a production environment where a path may point to somewhere evil, like an alias to /etc/passwd).

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Converts self into a target type. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
Pipes a value into a function that cannot ordinarily be called in suffix position. Read more
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
Pipes a dereference into a function that cannot normally be called in suffix position. Read more
Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more
Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
Provides immutable access for inspection. Read more
Calls tap in debug builds, and does nothing in release builds.
Provides mutable access for modification. Read more
Calls tap_mut in debug builds, and does nothing in release builds.
Provides immutable access to the reference for inspection.
Calls tap_ref in debug builds, and does nothing in release builds.
Provides mutable access to the reference for modification.
Calls tap_ref_mut in debug builds, and does nothing in release builds.
Provides immutable access to the borrow for inspection. Read more
Calls tap_borrow in debug builds, and does nothing in release builds.
Provides mutable access to the borrow for modification.
Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more
Immutably dereferences self for inspection.
Calls tap_deref in debug builds, and does nothing in release builds.
Mutably dereferences self for modification.
Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more
Attempts to convert self into T using TryInto<T>. Read more
Attempts to convert self into a target type. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.