Struct memory_serve::MemoryServe

source ·
pub struct MemoryServe { /* private fields */ }
Expand description

Helper struct to create and configure an axum to serve static files from memory. Initiate an instance with the MemoryServe::new method and pass a call to the load_assets! macro as the single argument.

Implementations§

source§

impl MemoryServe

source

pub fn new(assets: &'static [Asset]) -> Self

Initiate a MemoryServe instance, takes the output of load_assets! as an argument. load_assets! takes a directory name relative from the project root.

source

pub fn index_file(self, index_file: Option<&'static str>) -> Self

Which static file to serve on the route “/” (the index) The path (or route) should be relative to the directory passed to the load_assets! macro, but prepended with a slash. By default this is Some("/index.html")

source

pub fn fallback(self, fallback: Option<&'static str>) -> Self

Which static file to serve when no other routes are matched, also see fallback The path (or route) should be relative to the directory passed to the load_assets! macro, but prepended with a slash. By default this is None, which means axum will return an empty response with a HTTP 404 status code when no route matches.

source

pub fn fallback_status(self, fallback_status: StatusCode) -> Self

What HTTP status code to return when a static file is returned by the fallback handler.

source

pub fn enable_gzip(self, enable_gzip: bool) -> Self

Whether to enable gzip compression. When set to true, clients that accept gzip compressed files, but not brotli compressed files, are served gzip compressed files.

source

pub fn enable_brotli(self, enable_brotli: bool) -> Self

Whether to enable brotli compression. When set to true, clients that accept brotli compressed files are served brotli compressed files.

source

pub fn html_cache_control(self, html_cache_control: CacheControl) -> Self

The Cache-Control header to set for HTML files. See Cache control for options.

source

pub fn cache_control(self, cache_control: CacheControl) -> Self

Cache header to non-HTML files. See Cache control for options.

source

pub fn add_alias(self, from: &'static str, to: &'static str) -> Self

Create an alias for a route / file

source

pub fn into_router<S>(self) -> Router<S>
where S: Clone + Send + Sync + 'static,

Create an axum Router instance that will serve the included static assets Caution! This method leaks memory. It should only be called once (at startup).

Trait Implementations§

source§

impl Debug for MemoryServe

source§

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

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

impl Default for MemoryServe

source§

fn default() -> MemoryServe

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more