mirror of https://github.com/fafhrd91/actix-web
feat: Add fix to visibility warning and apply code format
This commit is contained in:
parent
b47530d66a
commit
9f2b207137
|
@ -1,6 +1,6 @@
|
||||||
//! Based on https://github.com/ibraheemdev/matchit/blob/master/benches/bench.rs
|
//! Based on https://github.com/ibraheemdev/matchit/blob/master/benches/bench.rs
|
||||||
|
|
||||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
macro_rules! register {
|
macro_rules! register {
|
||||||
(colon) => {{
|
(colon) => {{
|
||||||
|
|
|
@ -8,7 +8,7 @@ use serde::{de, Deserialize};
|
||||||
use crate::{de::PathDeserializer, Resource, ResourcePath};
|
use crate::{de::PathDeserializer, Resource, ResourcePath};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) enum PathItem {
|
pub enum PathItem {
|
||||||
Static(Cow<'static, str>),
|
Static(Cow<'static, str>),
|
||||||
Segment(u16, u16),
|
Segment(u16, u16),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
use std::{
|
use std::{
|
||||||
borrow::{Borrow, Cow},
|
borrow::{Borrow, Cow},
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
hash::{BuildHasher, Hash, Hasher}
|
hash::{BuildHasher, Hash, Hasher},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
IntoPatterns,
|
|
||||||
path::PathItem,
|
path::PathItem,
|
||||||
Patterns, regex_set::{escape, Regex, RegexSet}, Resource,
|
regex_set::{escape, Regex, RegexSet},
|
||||||
|
IntoPatterns, Patterns, Resource,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_DYNAMIC_SEGMENTS: usize = 16;
|
const MAX_DYNAMIC_SEGMENTS: usize = 16;
|
||||||
|
@ -645,7 +645,7 @@ impl ResourceDef {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn resolve_path_if_matches<R: Resource>(&self, resource: &mut R) -> bool {
|
pub fn resolve_path_if_matches<R: Resource>(&self, resource: &mut R) -> bool {
|
||||||
match self.capture_match_info(resource) {
|
match self.capture_match_info(resource) {
|
||||||
None => { false }
|
None => false,
|
||||||
Some(match_info) => {
|
Some(match_info) => {
|
||||||
resource.resolve_path(match_info);
|
resource.resolve_path(match_info);
|
||||||
true
|
true
|
||||||
|
@ -698,7 +698,9 @@ impl ResourceDef {
|
||||||
let path_str = path.unprocessed();
|
let path_str = path.unprocessed();
|
||||||
match &self.pat_type {
|
match &self.pat_type {
|
||||||
PatternType::Static(pattern) => match self.static_match(pattern, path_str) {
|
PatternType::Static(pattern) => match self.static_match(pattern, path_str) {
|
||||||
Some(len) => Some(ResourceMatchInfo::Static { matched_len: len as u16 }),
|
Some(len) => Some(ResourceMatchInfo::Static {
|
||||||
|
matched_len: len as u16,
|
||||||
|
}),
|
||||||
None => return None,
|
None => return None,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use crate::Path;
|
|
||||||
use crate::resource::ResourceMatchInfo;
|
use crate::resource::ResourceMatchInfo;
|
||||||
|
use crate::Path;
|
||||||
|
|
||||||
// TODO: this trait is necessary, document it
|
// TODO: this trait is necessary, document it
|
||||||
// see impl Resource for ServiceRequest
|
// see impl Resource for ServiceRequest
|
||||||
|
@ -17,7 +17,11 @@ pub trait Resource {
|
||||||
ResourceMatchInfo::Static { matched_len } => {
|
ResourceMatchInfo::Static { matched_len } => {
|
||||||
path.skip(matched_len);
|
path.skip(matched_len);
|
||||||
}
|
}
|
||||||
ResourceMatchInfo::Dynamic { matched_len, matched_vars, mut segments } => {
|
ResourceMatchInfo::Dynamic {
|
||||||
|
matched_len,
|
||||||
|
matched_vars,
|
||||||
|
mut segments,
|
||||||
|
} => {
|
||||||
for i in 0..matched_vars.len() {
|
for i in 0..matched_vars.len() {
|
||||||
path.add(matched_vars[i], mem::take(&mut segments[i]));
|
path.add(matched_vars[i], mem::take(&mut segments[i]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@ pub struct Router<T, U = ()> {
|
||||||
impl<T, U> Router<T, U> {
|
impl<T, U> Router<T, U> {
|
||||||
/// Constructs new `RouterBuilder` with empty route list.
|
/// Constructs new `RouterBuilder` with empty route list.
|
||||||
pub fn build() -> RouterBuilder<T, U> {
|
pub fn build() -> RouterBuilder<T, U> {
|
||||||
RouterBuilder { routes: Vec::new(), path_conflicts: vec![] }
|
RouterBuilder {
|
||||||
|
routes: Vec::new(),
|
||||||
|
path_conflicts: vec![],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the value in the router that matches a given [routing resource](Resource).
|
/// Finds the value in the router that matches a given [routing resource](Resource).
|
||||||
|
@ -118,8 +121,11 @@ impl<T, U> RouterBuilder<T, U> {
|
||||||
val: T,
|
val: T,
|
||||||
ctx: U,
|
ctx: U,
|
||||||
) -> (&mut ResourceDef, &mut T, &mut U) {
|
) -> (&mut ResourceDef, &mut T, &mut U) {
|
||||||
if let Some((_, path_conflicts)) = self.path_conflicts.iter_mut()
|
if let Some((_, path_conflicts)) = self
|
||||||
.find(|(current_rdef, _)| rdef.eq(current_rdef)) {
|
.path_conflicts
|
||||||
|
.iter_mut()
|
||||||
|
.find(|(current_rdef, _)| rdef.eq(current_rdef))
|
||||||
|
{
|
||||||
*path_conflicts += 1;
|
*path_conflicts += 1;
|
||||||
} else {
|
} else {
|
||||||
self.path_conflicts.push((rdef.clone(), 1));
|
self.path_conflicts.push((rdef.clone(), 1));
|
||||||
|
@ -135,7 +141,9 @@ impl<T, U> RouterBuilder<T, U> {
|
||||||
|
|
||||||
/// Finish configuration and create router instance.
|
/// Finish configuration and create router instance.
|
||||||
pub fn finish(self) -> Router<T, U> {
|
pub fn finish(self) -> Router<T, U> {
|
||||||
let max_path_conflicts = self.path_conflicts.iter()
|
let max_path_conflicts = self
|
||||||
|
.path_conflicts
|
||||||
|
.iter()
|
||||||
.map(|(_, path_conflicts)| *path_conflicts)
|
.map(|(_, path_conflicts)| *path_conflicts)
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
|
@ -345,7 +353,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(router.recognize_fn(&mut Path::new("/test2"), failures_until_fn_builder(3)).is_none());
|
assert!(router
|
||||||
assert!(router.recognize_fn(&mut Path::new("/test2"), failures_until_fn_builder(2)).is_some());
|
.recognize_fn(&mut Path::new("/test2"), failures_until_fn_builder(3))
|
||||||
|
.is_none());
|
||||||
|
assert!(router
|
||||||
|
.recognize_fn(&mut Path::new("/test2"), failures_until_fn_builder(2))
|
||||||
|
.is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,14 @@ use crate::{
|
||||||
config::{AppConfig, AppService},
|
config::{AppConfig, AppService},
|
||||||
data::FnDataFactory,
|
data::FnDataFactory,
|
||||||
dev::Extensions,
|
dev::Extensions,
|
||||||
Error,
|
|
||||||
guard::Guard,
|
guard::Guard,
|
||||||
HttpResponse,
|
|
||||||
request::{HttpRequest, HttpRequestPool},
|
request::{HttpRequest, HttpRequestPool},
|
||||||
rmap::ResourceMap, service::{
|
rmap::ResourceMap,
|
||||||
|
service::{
|
||||||
AppServiceFactory, BoxedHttpService, BoxedHttpServiceFactory, ServiceRequest,
|
AppServiceFactory, BoxedHttpService, BoxedHttpServiceFactory, ServiceRequest,
|
||||||
ServiceResponse,
|
ServiceResponse,
|
||||||
},
|
},
|
||||||
|
Error, HttpResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Service factory to convert [`Request`] to a [`ServiceRequest<S>`].
|
/// Service factory to convert [`Request`] to a [`ServiceRequest<S>`].
|
||||||
|
@ -347,15 +347,15 @@ impl ServiceFactory<ServiceRequest> for AppEntry {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
Arc,
|
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
App,
|
test::{init_service, TestRequest},
|
||||||
HttpResponse, test::{init_service, TestRequest}, web,
|
web, App, HttpResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DropData(Arc<AtomicBool>);
|
struct DropData(Arc<AtomicBool>);
|
||||||
|
|
|
@ -14,13 +14,13 @@ use crate::{
|
||||||
config::ServiceConfig,
|
config::ServiceConfig,
|
||||||
data::Data,
|
data::Data,
|
||||||
dev::AppService,
|
dev::AppService,
|
||||||
Error,
|
|
||||||
guard::Guard,
|
guard::Guard,
|
||||||
Resource,
|
rmap::ResourceMap,
|
||||||
rmap::ResourceMap, Route, service::{
|
service::{
|
||||||
AppServiceFactory, BoxedHttpService, BoxedHttpServiceFactory, HttpServiceFactory,
|
AppServiceFactory, BoxedHttpService, BoxedHttpServiceFactory, HttpServiceFactory,
|
||||||
ServiceFactoryWrapper, ServiceRequest, ServiceResponse,
|
ServiceFactoryWrapper, ServiceRequest, ServiceResponse,
|
||||||
},
|
},
|
||||||
|
Error, Resource, Route,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Guards = Vec<Box<dyn Guard>>;
|
type Guards = Vec<Box<dyn Guard>>;
|
||||||
|
@ -554,14 +554,14 @@ mod tests {
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
App,
|
|
||||||
guard,
|
guard,
|
||||||
http::{
|
http::{
|
||||||
header::{self, HeaderValue},
|
header::{self, HeaderValue},
|
||||||
Method, StatusCode,
|
Method, StatusCode,
|
||||||
},
|
},
|
||||||
HttpMessage,
|
middleware::DefaultHeaders,
|
||||||
HttpRequest, HttpResponse, middleware::DefaultHeaders, test::{assert_body_eq, call_service, init_service, read_body, TestRequest}, web,
|
test::{assert_body_eq, call_service, init_service, read_body, TestRequest},
|
||||||
|
web, App, HttpMessage, HttpRequest, HttpResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue