mirror of
https://github.com/actix/actix-web.git
synced 2024-12-29 19:40:34 +00:00
more simplification for RouteRecognizer
This commit is contained in:
parent
d9b89ccdac
commit
779b480663
2 changed files with 13 additions and 2 deletions
|
@ -13,7 +13,16 @@ pub const HTTPOk: StaticResponse = StaticResponse(StatusCode::OK);
|
|||
pub const HTTPCreated: StaticResponse = StaticResponse(StatusCode::CREATED);
|
||||
pub const HTTPNoContent: StaticResponse = StaticResponse(StatusCode::NO_CONTENT);
|
||||
|
||||
pub const HTTPMultipleChoices: StaticResponse = StaticResponse(StatusCode::MULTIPLE_CHOICES);
|
||||
pub const HTTPMovedPermanenty: StaticResponse = StaticResponse(StatusCode::MOVED_PERMANENTLY);
|
||||
pub const HTTPFound: StaticResponse = StaticResponse(StatusCode::FOUND);
|
||||
pub const HTTPSeeOther: StaticResponse = StaticResponse(StatusCode::SEE_OTHER);
|
||||
pub const HTTPNotModified: StaticResponse = StaticResponse(StatusCode::NOT_MODIFIED);
|
||||
pub const HTTPUseProxy: StaticResponse = StaticResponse(StatusCode::USE_PROXY);
|
||||
pub const HTTPTemporaryRedirect: StaticResponse =
|
||||
StaticResponse(StatusCode::TEMPORARY_REDIRECT);
|
||||
pub const HTTPPermanentRedirect: StaticResponse =
|
||||
StaticResponse(StatusCode::PERMANENT_REDIRECT);
|
||||
|
||||
pub const HTTPBadRequest: StaticResponse = StaticResponse(StatusCode::BAD_REQUEST);
|
||||
pub const HTTPNotFound: StaticResponse = StaticResponse(StatusCode::NOT_FOUND);
|
||||
|
|
|
@ -25,7 +25,9 @@ impl<T> Default for RouteRecognizer<T> {
|
|||
|
||||
impl<T> RouteRecognizer<T> {
|
||||
|
||||
pub fn new(prefix: String, routes: Vec<(String, T)>) -> Self {
|
||||
pub fn new<P: ToString, U>(prefix: P, routes: U) -> Self
|
||||
where U: IntoIterator<Item=(String, T)>
|
||||
{
|
||||
let mut paths = Vec::new();
|
||||
let mut handlers = Vec::new();
|
||||
for item in routes {
|
||||
|
@ -36,7 +38,7 @@ impl<T> RouteRecognizer<T> {
|
|||
let regset = RegexSet::new(&paths);
|
||||
|
||||
RouteRecognizer {
|
||||
prefix: prefix.len() - 1,
|
||||
prefix: prefix.to_string().len() - 1,
|
||||
patterns: regset.unwrap(),
|
||||
routes: handlers,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue