mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 06:54:46 +00:00
merge workspace and main crate
This commit is contained in:
parent
52679ad29d
commit
5587ded60d
45 changed files with 58 additions and 67 deletions
35
src/matcher/mod.rs
Normal file
35
src/matcher/mod.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use itertools::Itertools;
|
||||
use mime::Mime;
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod accept;
|
||||
pub use accept::AcceptHeaderMatcher;
|
||||
|
||||
mod content_type;
|
||||
pub use content_type::ContentTypeMatcher;
|
||||
|
||||
type LookupTable = HashMap<String, Vec<usize>>;
|
||||
|
||||
trait LookupTableFromTypes
|
||||
{
|
||||
fn from_types<'a, I : Iterator<Item = &'a Mime>>(types : I, include_stars : bool) -> Self;
|
||||
}
|
||||
|
||||
impl LookupTableFromTypes for LookupTable
|
||||
{
|
||||
fn from_types<'a, I : Iterator<Item = &'a Mime>>(types : I, include_stars : bool) -> Self
|
||||
{
|
||||
if include_stars
|
||||
{
|
||||
return types
|
||||
.enumerate()
|
||||
.flat_map(|(i, mime)| vec![("*/*".to_owned(), i), (format!("{}/*", mime.type_()), i), (mime.essence_str().to_owned(), i)].into_iter())
|
||||
.into_group_map();
|
||||
}
|
||||
|
||||
types
|
||||
.enumerate()
|
||||
.map(|(i, mime)| (mime.essence_str().to_owned(), i))
|
||||
.into_group_map()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue