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 theRustEmbedandClonetrait. 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>
impl<E: RustEmbed + Clone> ServeEmbed<E>
Sourcepub fn new() -> Self
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.
Sourcepub fn with_parameters(
fallback_file: Option<String>,
fallback_behavior: FallbackBehavior,
index_file: Option<String>,
) -> Self
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. IfNone, a default 404 response is served.fallback_behavior: The behavior of the server when a requested file is not found. Please seeFallbackBehaviorfor more information.index_file: The name of the file to serve when a directory is accessed. IfNone, a 404 response is served for directory.
§Returns
A new ServeEmbed instance.
Trait Implementations§
Source§impl<E: Clone + RustEmbed + Clone> Clone for ServeEmbed<E>
impl<E: Clone + RustEmbed + Clone> Clone for ServeEmbed<E>
Source§fn clone(&self) -> ServeEmbed<E>
fn clone(&self) -> ServeEmbed<E>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<E: RustEmbed + Clone, T: Send + 'static> Service<Request<T>> for ServeEmbed<E>
impl<E: RustEmbed + Clone, T: Send + 'static> Service<Request<T>> for ServeEmbed<E>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more