mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-30 08:24:28 +02:00
update msrv to 1.56 (#2777)
* update msrv to 1.56 * remove transitive dashmap dependency closes #2747
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
use std::ops::{DerefMut, Index};
|
||||
|
||||
use firestorm::profile_method;
|
||||
use serde::de;
|
||||
|
||||
use crate::{de::PathDeserializer, Resource, ResourcePath};
|
||||
@ -52,7 +51,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
/// Returns full path as a string.
|
||||
#[inline]
|
||||
pub fn as_str(&self) -> &str {
|
||||
profile_method!(as_str);
|
||||
self.path.path()
|
||||
}
|
||||
|
||||
@ -61,7 +59,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
/// Returns empty string if no more is to be processed.
|
||||
#[inline]
|
||||
pub fn unprocessed(&self) -> &str {
|
||||
profile_method!(unprocessed);
|
||||
// clamp skip to path length
|
||||
let skip = (self.skip as usize).min(self.as_str().len());
|
||||
&self.path.path()[skip..]
|
||||
@ -72,8 +69,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
#[deprecated(since = "0.6.0", note = "Use `.as_str()` or `.unprocessed()`.")]
|
||||
#[inline]
|
||||
pub fn path(&self) -> &str {
|
||||
profile_method!(path);
|
||||
|
||||
let skip = self.skip as usize;
|
||||
let path = self.path.path();
|
||||
if skip <= path.len() {
|
||||
@ -86,8 +81,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
/// Set new path.
|
||||
#[inline]
|
||||
pub fn set(&mut self, path: T) {
|
||||
profile_method!(set);
|
||||
|
||||
self.skip = 0;
|
||||
self.path = path;
|
||||
self.segments.clear();
|
||||
@ -96,8 +89,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
/// Reset state.
|
||||
#[inline]
|
||||
pub fn reset(&mut self) {
|
||||
profile_method!(reset);
|
||||
|
||||
self.skip = 0;
|
||||
self.segments.clear();
|
||||
}
|
||||
@ -105,13 +96,10 @@ impl<T: ResourcePath> Path<T> {
|
||||
/// Skip first `n` chars in path.
|
||||
#[inline]
|
||||
pub fn skip(&mut self, n: u16) {
|
||||
profile_method!(skip);
|
||||
self.skip += n;
|
||||
}
|
||||
|
||||
pub(crate) fn add(&mut self, name: impl Into<Cow<'static, str>>, value: PathItem) {
|
||||
profile_method!(add);
|
||||
|
||||
match value {
|
||||
PathItem::Static(s) => self.segments.push((name.into(), PathItem::Static(s))),
|
||||
PathItem::Segment(begin, end) => self.segments.push((
|
||||
@ -127,8 +115,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
name: impl Into<Cow<'static, str>>,
|
||||
value: impl Into<Cow<'static, str>>,
|
||||
) {
|
||||
profile_method!(add_static);
|
||||
|
||||
self.segments
|
||||
.push((name.into(), PathItem::Static(value.into())));
|
||||
}
|
||||
@ -147,8 +133,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
|
||||
/// Get matched parameter by name without type conversion
|
||||
pub fn get(&self, name: &str) -> Option<&str> {
|
||||
profile_method!(get);
|
||||
|
||||
for (seg_name, val) in self.segments.iter() {
|
||||
if name == seg_name {
|
||||
return match val {
|
||||
@ -167,8 +151,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
///
|
||||
/// If keyed parameter is not available empty string is used as default value.
|
||||
pub fn query(&self, key: &str) -> &str {
|
||||
profile_method!(query);
|
||||
|
||||
if let Some(s) = self.get(key) {
|
||||
s
|
||||
} else {
|
||||
@ -186,7 +168,6 @@ impl<T: ResourcePath> Path<T> {
|
||||
|
||||
/// Try to deserialize matching parameters to a specified type `U`
|
||||
pub fn load<'de, U: serde::Deserialize<'de>>(&'de self) -> Result<U, de::value::Error> {
|
||||
profile_method!(load);
|
||||
de::Deserialize::deserialize(PathDeserializer::new(self))
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ use std::{
|
||||
mem,
|
||||
};
|
||||
|
||||
use firestorm::{profile_fn, profile_method, profile_section};
|
||||
use regex::{escape, Regex, RegexSet};
|
||||
use tracing::error;
|
||||
|
||||
@ -272,7 +271,6 @@ impl ResourceDef {
|
||||
/// assert!(!resource.is_match("/foo"));
|
||||
/// ```
|
||||
pub fn new<T: IntoPatterns>(paths: T) -> Self {
|
||||
profile_method!(new);
|
||||
Self::construct(paths, false)
|
||||
}
|
||||
|
||||
@ -300,7 +298,6 @@ impl ResourceDef {
|
||||
/// assert!(!resource.is_match("/foo"));
|
||||
/// ```
|
||||
pub fn prefix<T: IntoPatterns>(paths: T) -> Self {
|
||||
profile_method!(prefix);
|
||||
ResourceDef::construct(paths, true)
|
||||
}
|
||||
|
||||
@ -325,7 +322,6 @@ impl ResourceDef {
|
||||
/// assert!(!resource.is_match("user/123"));
|
||||
/// ```
|
||||
pub fn root_prefix(path: &str) -> Self {
|
||||
profile_method!(root_prefix);
|
||||
ResourceDef::prefix(insert_slash(path).into_owned())
|
||||
}
|
||||
|
||||
@ -549,8 +545,6 @@ impl ResourceDef {
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn is_match(&self, path: &str) -> bool {
|
||||
profile_method!(is_match);
|
||||
|
||||
// this function could be expressed as:
|
||||
// `self.find_match(path).is_some()`
|
||||
// but this skips some checks and uses potentially faster regex methods
|
||||
@ -598,8 +592,6 @@ impl ResourceDef {
|
||||
/// assert_eq!(resource.find_match("/profile/1234"), Some(13));
|
||||
/// ```
|
||||
pub fn find_match(&self, path: &str) -> Option<usize> {
|
||||
profile_method!(find_match);
|
||||
|
||||
match &self.pat_type {
|
||||
PatternType::Static(pattern) => self.static_match(pattern, path),
|
||||
|
||||
@ -634,7 +626,6 @@ impl ResourceDef {
|
||||
/// assert_eq!(path.unprocessed(), "");
|
||||
/// ```
|
||||
pub fn capture_match_info<R: Resource>(&self, resource: &mut R) -> bool {
|
||||
profile_method!(capture_match_info);
|
||||
self.capture_match_info_fn(resource, |_| true)
|
||||
}
|
||||
|
||||
@ -680,53 +671,35 @@ impl ResourceDef {
|
||||
R: Resource,
|
||||
F: FnOnce(&R) -> bool,
|
||||
{
|
||||
profile_method!(capture_match_info_fn);
|
||||
|
||||
let mut segments = <[PathItem; MAX_DYNAMIC_SEGMENTS]>::default();
|
||||
let path = resource.resource_path();
|
||||
let path_str = path.unprocessed();
|
||||
|
||||
let (matched_len, matched_vars) = match &self.pat_type {
|
||||
PatternType::Static(pattern) => {
|
||||
profile_section!(pattern_static_or_prefix);
|
||||
|
||||
match self.static_match(pattern, path_str) {
|
||||
Some(len) => (len, None),
|
||||
None => return false,
|
||||
}
|
||||
}
|
||||
PatternType::Static(pattern) => match self.static_match(pattern, path_str) {
|
||||
Some(len) => (len, None),
|
||||
None => return false,
|
||||
},
|
||||
|
||||
PatternType::Dynamic(re, names) => {
|
||||
profile_section!(pattern_dynamic);
|
||||
|
||||
let captures = {
|
||||
profile_section!(pattern_dynamic_regex_exec);
|
||||
|
||||
match re.captures(path.unprocessed()) {
|
||||
Some(captures) => captures,
|
||||
_ => return false,
|
||||
}
|
||||
let captures = match re.captures(path.unprocessed()) {
|
||||
Some(captures) => captures,
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
{
|
||||
profile_section!(pattern_dynamic_extract_captures);
|
||||
|
||||
for (no, name) in names.iter().enumerate() {
|
||||
if let Some(m) = captures.name(name) {
|
||||
segments[no] = PathItem::Segment(m.start() as u16, m.end() as u16);
|
||||
} else {
|
||||
error!("Dynamic path match but not all segments found: {}", name);
|
||||
return false;
|
||||
}
|
||||
for (no, name) in names.iter().enumerate() {
|
||||
if let Some(m) = captures.name(name) {
|
||||
segments[no] = PathItem::Segment(m.start() as u16, m.end() as u16);
|
||||
} else {
|
||||
error!("Dynamic path match but not all segments found: {}", name);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
(captures[1].len(), Some(names))
|
||||
}
|
||||
|
||||
PatternType::DynamicSet(re, params) => {
|
||||
profile_section!(pattern_dynamic_set);
|
||||
|
||||
let path = path.unprocessed();
|
||||
let (pattern, names) = match re.matches(path).into_iter().next() {
|
||||
Some(idx) => ¶ms[idx],
|
||||
@ -809,7 +782,6 @@ impl ResourceDef {
|
||||
I: IntoIterator,
|
||||
I::Item: AsRef<str>,
|
||||
{
|
||||
profile_method!(resource_path_from_iter);
|
||||
let mut iter = values.into_iter();
|
||||
self.build_resource_path(path, |_| iter.next())
|
||||
}
|
||||
@ -845,7 +817,6 @@ impl ResourceDef {
|
||||
V: AsRef<str>,
|
||||
S: BuildHasher,
|
||||
{
|
||||
profile_method!(resource_path_from_map);
|
||||
self.build_resource_path(path, |name| values.get(name))
|
||||
}
|
||||
|
||||
@ -866,8 +837,6 @@ impl ResourceDef {
|
||||
}
|
||||
|
||||
fn construct<T: IntoPatterns>(paths: T, is_prefix: bool) -> Self {
|
||||
profile_method!(construct);
|
||||
|
||||
let patterns = paths.patterns();
|
||||
let (pat_type, segments) = match &patterns {
|
||||
Patterns::Single(pattern) => ResourceDef::parse(pattern, is_prefix, false),
|
||||
@ -926,8 +895,6 @@ impl ResourceDef {
|
||||
/// # Panics
|
||||
/// Panics if given patterns does not contain a dynamic segment.
|
||||
fn parse_param(pattern: &str) -> (PatternSegment, String, &str, bool) {
|
||||
profile_method!(parse_param);
|
||||
|
||||
const DEFAULT_PATTERN: &str = "[^/]+";
|
||||
const DEFAULT_PATTERN_TAIL: &str = ".*";
|
||||
|
||||
@ -997,8 +964,6 @@ impl ResourceDef {
|
||||
is_prefix: bool,
|
||||
force_dynamic: bool,
|
||||
) -> (PatternType, Vec<PatternSegment>) {
|
||||
profile_method!(parse);
|
||||
|
||||
if !force_dynamic && pattern.find('{').is_none() && !pattern.ends_with('*') {
|
||||
// pattern is static
|
||||
return (
|
||||
@ -1131,8 +1096,6 @@ impl From<String> for ResourceDef {
|
||||
}
|
||||
|
||||
pub(crate) fn insert_slash(path: &str) -> Cow<'_, str> {
|
||||
profile_fn!(insert_slash);
|
||||
|
||||
if !path.is_empty() && !path.starts_with('/') {
|
||||
let mut new_path = String::with_capacity(path.len() + 1);
|
||||
new_path.push('/');
|
||||
|
@ -1,5 +1,3 @@
|
||||
use firestorm::profile_method;
|
||||
|
||||
use crate::{IntoPatterns, Resource, ResourceDef};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
@ -30,7 +28,6 @@ impl<T, U> Router<T, U> {
|
||||
where
|
||||
R: Resource,
|
||||
{
|
||||
profile_method!(recognize);
|
||||
self.recognize_fn(resource, |_, _| true)
|
||||
}
|
||||
|
||||
@ -39,7 +36,6 @@ impl<T, U> Router<T, U> {
|
||||
where
|
||||
R: Resource,
|
||||
{
|
||||
profile_method!(recognize_mut);
|
||||
self.recognize_mut_fn(resource, |_, _| true)
|
||||
}
|
||||
|
||||
@ -55,8 +51,6 @@ impl<T, U> Router<T, U> {
|
||||
R: Resource,
|
||||
F: FnMut(&R, &U) -> bool,
|
||||
{
|
||||
profile_method!(recognize_checked);
|
||||
|
||||
for (rdef, val, ctx) in self.routes.iter() {
|
||||
if rdef.capture_match_info_fn(resource, |res| check(res, ctx)) {
|
||||
return Some((val, ResourceId(rdef.id())));
|
||||
@ -77,8 +71,6 @@ impl<T, U> Router<T, U> {
|
||||
R: Resource,
|
||||
F: FnMut(&R, &U) -> bool,
|
||||
{
|
||||
profile_method!(recognize_mut_checked);
|
||||
|
||||
for (rdef, val, ctx) in self.routes.iter_mut() {
|
||||
if rdef.capture_match_info_fn(resource, |res| check(res, ctx)) {
|
||||
return Some((val, ResourceId(rdef.id())));
|
||||
@ -104,7 +96,6 @@ impl<T, U> RouterBuilder<T, U> {
|
||||
val: T,
|
||||
ctx: U,
|
||||
) -> (&mut ResourceDef, &mut T, &mut U) {
|
||||
profile_method!(push);
|
||||
self.routes.push((rdef, val, ctx));
|
||||
self.routes
|
||||
.last_mut()
|
||||
@ -131,7 +122,6 @@ where
|
||||
path: impl IntoPatterns,
|
||||
val: T,
|
||||
) -> (&mut ResourceDef, &mut T, &mut U) {
|
||||
profile_method!(path);
|
||||
self.push(ResourceDef::new(path), val, U::default())
|
||||
}
|
||||
|
||||
@ -141,13 +131,11 @@ where
|
||||
prefix: impl IntoPatterns,
|
||||
val: T,
|
||||
) -> (&mut ResourceDef, &mut T, &mut U) {
|
||||
profile_method!(prefix);
|
||||
self.push(ResourceDef::prefix(prefix), val, U::default())
|
||||
}
|
||||
|
||||
/// Registers resource for [`ResourceDef`].
|
||||
pub fn rdef(&mut self, rdef: ResourceDef, val: T) -> (&mut ResourceDef, &mut T, &mut U) {
|
||||
profile_method!(rdef);
|
||||
self.push(rdef, val, U::default())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user