1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-19 22:44:38 +00:00
deprecated-gotham-restful/src/matcher/mod.rs

36 lines
827 B
Rust
Raw Normal View History

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
{
2020-05-03 18:21:50 +02:00
return types
.enumerate()
.flat_map(|(i, mime)| vec![("*/*".to_owned(), i), (format!("{}/*", mime.type_()), i), (mime.essence_str().to_owned(), i)].into_iter())
2020-05-03 18:21:50 +02:00
.into_group_map();
}
2020-05-03 18:21:50 +02:00
types
.enumerate()
.map(|(i, mime)| (mime.essence_str().to_owned(), i))
.into_group_map()
}
}