Struct ServeEmbed

Source
pub struct ServeEmbed<E: RustEmbed + Clone> { /* private fields */ }
Expand description

ServeEmbed is a struct that represents a service for serving embedded files.

§Parameters

  • E: A type that implements the RustEmbed and Clone trait. This type represents the embedded files.

§Example

#[derive(RustEmbed, Clone)]
#[folder = "examples/assets/"]
struct Assets;

let listener = TcpListener::bind("127.0.0.1:8080").await?;
let serve_assets = ServeEmbed::<Assets>::new();
let app = axum::Router::new().nest_service("/", serve_assets);
axum::serve(listener, app).await?;

Implementations§

Source§

impl<E: RustEmbed + Clone> ServeEmbed<E>

Source

pub fn new() -> Self

Constructs a new ServeEmbed instance with default parameters.

This function calls with_parameters internally with None for fallback_file, FallbackBehavior::NotFound for fallback_behavior, and "index.html" for index_file.

§Returns

A new ServeEmbed instance with default parameters.

Source

pub fn with_parameters( fallback_file: Option<String>, fallback_behavior: FallbackBehavior, index_file: Option<String>, ) -> Self

Constructs a new ServeEmbed instance with the provided parameters.

§Parameters
  • fallback_file: The path of the file to serve when a requested file is not found. If None, a default 404 response is served.
  • fallback_behavior: The behavior of the server when a requested file is not found. Please see FallbackBehavior for more information.
  • index_file: The name of the file to serve when a directory is accessed. If None, a 404 response is served for directory.
§Returns

A new ServeEmbed instance.

Trait Implementations§

Source§

impl<E: Clone + RustEmbed + Clone> Clone for ServeEmbed<E>

Source§

fn clone(&self) -> ServeEmbed<E>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Debug + RustEmbed + Clone> Debug for ServeEmbed<E>

Source§

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

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

impl<E: RustEmbed + Clone, T: Send + 'static> Service<Request<T>> for ServeEmbed<E>

Source§

type Response = Response<Body>

Responses given by the service.
Source§

type Error = Infallible

Errors produced by the service.
Source§

type Future = ServeFuture<E, T>

The future response value.
Source§

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
Source§

fn call(&mut self, req: Request<T>) -> Self::Future

Process the request and return the response asynchronously. Read more

Auto Trait Implementations§

§

impl<E> Freeze for ServeEmbed<E>

§

impl<E> RefUnwindSafe for ServeEmbed<E>
where E: RefUnwindSafe,

§

impl<E> Send for ServeEmbed<E>
where E: Send,

§

impl<E> Sync for ServeEmbed<E>
where E: Sync,

§

impl<E> Unpin for ServeEmbed<E>
where E: Unpin,

§

impl<E> UnwindSafe for ServeEmbed<E>
where E: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.