1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-11 17:59:35 +00:00

move path impls to derives

This commit is contained in:
Rob Ede 2022-01-22 04:02:34 +00:00
parent acacb90b2e
commit c25dd23820
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
3 changed files with 11 additions and 40 deletions

View file

@ -37,7 +37,7 @@ use crate::{
/// .service(Files::new("/static", "."));
/// ```
pub struct Files {
path: String,
mount_path: String,
directory: PathBuf,
index: Option<String>,
show_index: bool,
@ -68,7 +68,7 @@ impl Clone for Files {
default: self.default.clone(),
renderer: self.renderer.clone(),
file_flags: self.file_flags,
path: self.path.clone(),
mount_path: self.mount_path.clone(),
mime_override: self.mime_override.clone(),
path_filter: self.path_filter.clone(),
use_guards: self.use_guards.clone(),
@ -107,7 +107,7 @@ impl Files {
};
Files {
path: mount_path.trim_end_matches('/').to_owned(),
mount_path: mount_path.trim_end_matches('/').to_owned(),
directory: dir,
index: None,
show_index: false,
@ -342,9 +342,9 @@ impl HttpServiceFactory for Files {
}
let rdef = if config.is_root() {
ResourceDef::root_prefix(&self.path)
ResourceDef::root_prefix(&self.mount_path)
} else {
ResourceDef::prefix(&self.path)
ResourceDef::prefix(&self.mount_path)
};
config.register_service(rdef, guards, self, None)

View file

@ -168,7 +168,7 @@ impl Service<ServiceRequest> for FilesService {
}
}
None if this.show_index => Ok(this.show_index(req, path)),
_ => Ok(ServiceResponse::from_err(
None => Ok(ServiceResponse::from_err(
FilesError::IsDirectory,
req.into_parts().0,
)),

View file

@ -1,9 +1,10 @@
//! For path segment extractor documentation, see [`Path`].
use std::{fmt, ops, sync::Arc};
use std::sync::Arc;
use actix_router::PathDeserializer;
use actix_utils::future::{ready, Ready};
use derive_more::{AsRef, Deref, DerefMut, Display, From};
use serde::de;
use crate::{
@ -49,7 +50,9 @@ use crate::{
/// format!("Welcome {}!", info.name)
/// }
/// ```
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From,
)]
pub struct Path<T>(T);
impl<T> Path<T> {
@ -59,38 +62,6 @@ impl<T> Path<T> {
}
}
impl<T> AsRef<T> for Path<T> {
fn as_ref(&self) -> &T {
&self.0
}
}
impl<T> ops::Deref for Path<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
impl<T> ops::DerefMut for Path<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}
impl<T> From<T> for Path<T> {
fn from(inner: T) -> Path<T> {
Path(inner)
}
}
impl<T: fmt::Display> fmt::Display for Path<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
/// See [here](#Examples) for example of usage as an extractor.
impl<T> FromRequest for Path<T>
where