pub struct ResourceFiles { /* private fields */ }
Expand description
Static resource files handling
ResourceFiles
service must be registered with App::service
method.
use std::collections::HashMap;
use actix_web::App;
fn main() {
// serve root directory with default options:
// - resolve index.html
let files: HashMap<&'static str, actix_plus_static_files::Resource> = HashMap::new();
let app = App::new()
.service(actix_plus_static_files::ResourceFiles::new("/", files));
// or subpath with additional option to not resolve index.html
let files: HashMap<&'static str, actix_plus_static_files::Resource> = HashMap::new();
let app = App::new()
.service(actix_plus_static_files::ResourceFiles::new("/imgs", files)
.do_not_resolve_defaults());
}
Implementations§
Source§impl ResourceFiles
impl ResourceFiles
pub fn new(path: &str, files: HashMap<&'static str, Resource>) -> Self
Sourcepub fn do_not_resolve_defaults(self) -> Self
pub fn do_not_resolve_defaults(self) -> Self
By default trying to resolve ‘…/’ to ‘…/index.html’ if it exists. Turn off this resolution by calling this function.
Sourcepub fn resolve_not_found_to<S: ToString>(self, path: S) -> Self
pub fn resolve_not_found_to<S: ToString>(self, path: S) -> Self
Resolves not found references to this path.
This can be useful for angular-like applications.
Sourcepub fn resolve_not_found_to_root(self) -> Self
pub fn resolve_not_found_to_root(self) -> Self
Resolves not found references to root path.
This can be useful for angular-like applications.
Trait Implementations§
Source§impl Deref for ResourceFiles
impl Deref for ResourceFiles
Source§impl HttpServiceFactory for ResourceFiles
impl HttpServiceFactory for ResourceFiles
fn register(self, config: &mut AppService)
Source§impl ServiceFactory for ResourceFiles
impl ServiceFactory for ResourceFiles
Source§type Request = ServiceRequest
type Request = ServiceRequest
Requests handled by the created services.
Source§type Response = ServiceResponse
type Response = ServiceResponse
Responses given by the created services.
Source§type Service = ResourceFilesService
type Service = ResourceFilesService
The kind of
Service
created by this factory.Source§type Future = Pin<Box<dyn Future<Output = Result<<ResourceFiles as ServiceFactory>::Service, <ResourceFiles as ServiceFactory>::InitError>>>>
type Future = Pin<Box<dyn Future<Output = Result<<ResourceFiles as ServiceFactory>::Service, <ResourceFiles as ServiceFactory>::InitError>>>>
The future of the
Service
instance.Source§fn new_service(&self, _: ()) -> Self::Future
fn new_service(&self, _: ()) -> Self::Future
Create and return a new service asynchronously.
Source§fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R>
fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R>
Map this service’s output to a different type, returning a new service
of the resulting type.
Source§fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E>
fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E>
Map this service’s error to a different error, returning a new service.
Source§fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>
Map this factory’s init error to a different error, returning a new service.
Auto Trait Implementations§
impl Freeze for ResourceFiles
impl RefUnwindSafe for ResourceFiles
impl !Send for ResourceFiles
impl !Sync for ResourceFiles
impl Unpin for ResourceFiles
impl UnwindSafe for ResourceFiles
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
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<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<T> IntoServiceFactory<T> for Twhere
T: ServiceFactory,
impl<T> IntoServiceFactory<T> for Twhere
T: ServiceFactory,
Source§fn into_factory(self) -> T
fn into_factory(self) -> T
Convert
Self
to a ServiceFactory