pub struct EmbeddedFileService {
pub directory: &'static str,
pub filename: &'static str,
pub bytes: &'static [u8],
pub etag: &'static str,
pub last_modified: &'static str,
pub content_type: Option<&'static str>,
}Expand description
A tower Service serving an embedded file.
Most easily obtained from the embed_file!() macro.
Most usefully, implements the flavor of tower Service required to use as an
axum handler.
By default, serves the embedded version of the file. For development use,
enable the feature serve-from-fs to load the contents dynamically from the
local file system.
§Example
use axum::{routing, Router};
use axum_embed_files::service::EmbeddedFileService;
fn router<S: Clone + Send + Sync + 'static>() -> Router<S> {
Router::new().route("/colophon.txt", routing::get_service(EmbeddedFileService {
directory: "/path/to/local/files",
filename: "include/colophon.txt",
bytes: b"This project was brought to you by Rust.",
etag: "\"V1\"",
last_modified: "Mon, 01 Jan 1970 00:00:00 GMT",
content_type: Some("text/plain"),
}))
}Fields§
§directory: &'static strThe base directory to find the file.
filename: &'static strThe path to the source file.
bytes: &'static [u8]The content of the file as bytes.
etag: &'static strAn ETag validator for the file, inclusive of quotes.
Consider using axum_embed_files_core::etag::generate.
last_modified: &'static strThe formatted last modified date of the file.
Consider using axum_embed_files_core::last_modified::of_path.
content_type: Option<&'static str>The file’s content type, if we know it.
Consider using axum_embed_files_core::content_type::guess_from_path.
Trait Implementations§
Source§impl Clone for EmbeddedFileService
impl Clone for EmbeddedFileService
Source§fn clone(&self) -> EmbeddedFileService
fn clone(&self) -> EmbeddedFileService
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EmbeddedFileService
impl Debug for EmbeddedFileService
Source§impl<B> Service<Request<B>> for EmbeddedFileService
impl<B> Service<Request<B>> for EmbeddedFileService
Source§type Error = Infallible
type Error = Infallible
Source§type Future = Ready<Result<<EmbeddedFileService as Service<Request<B>>>::Response, <EmbeddedFileService as Service<Request<B>>>::Error>>
type Future = Ready<Result<<EmbeddedFileService as Service<Request<B>>>::Response, <EmbeddedFileService as Service<Request<B>>>::Error>>
Auto Trait Implementations§
impl Freeze for EmbeddedFileService
impl RefUnwindSafe for EmbeddedFileService
impl Send for EmbeddedFileService
impl Sync for EmbeddedFileService
impl Unpin for EmbeddedFileService
impl UnwindSafe for EmbeddedFileService
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
Source§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService, that is a Service whose
response is another service. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<S, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<S, C>
MakeService, that will store C’s
associated ConnectInfo in a request extension such that ConnectInfo
can extract it. Read moreSource§fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
HandleError, that will handle errors
by converting them into responses. Read moreSource§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
Source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service, calling it with the provided request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>)
to a different value, regardless of whether the future succeeds or
fails. Read more