mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-30 03:10:25 +00:00
Move macro into separate file
This commit is contained in:
parent
749e700757
commit
0f7ca7ec87
2 changed files with 20 additions and 19 deletions
17
src/quirks/headers_macro.rs
Normal file
17
src/quirks/headers_macro.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Adapted from https://github.com/bluss/maplit for HeaderMaps
|
||||
macro_rules! headers {
|
||||
(@single $($x:tt)*) => (());
|
||||
(@count $($rest:expr),*) => (<[()]>::len(&[$(headers!(@single $rest)),*]));
|
||||
|
||||
($($key:expr => $value:expr,)+) => { headers!($($key => $value),+) };
|
||||
($($key:expr => $value:expr),*) => {
|
||||
{
|
||||
let _cap = headers!(@count $($key),*);
|
||||
let mut _map = headers::HeaderMap::with_capacity(_cap);
|
||||
$(
|
||||
let _ = _map.insert($key, $value);
|
||||
)*
|
||||
_map
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
#[macro_use]
|
||||
mod headers_macro;
|
||||
|
||||
use headers::HeaderMap;
|
||||
use http::{header::USER_AGENT, Method};
|
||||
use regex::Regex;
|
||||
|
|
@ -7,24 +10,6 @@ use reqwest::Url;
|
|||
const GOOGLEBOT: &'static str =
|
||||
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://google.com/bot.html)";
|
||||
|
||||
// Adapted from https://github.com/bluss/maplit for HeaderMaps
|
||||
macro_rules! headers {
|
||||
(@single $($x:tt)*) => (());
|
||||
(@count $($rest:expr),*) => (<[()]>::len(&[$(headers!(@single $rest)),*]));
|
||||
|
||||
($($key:expr => $value:expr,)+) => { headers!($($key => $value),+) };
|
||||
($($key:expr => $value:expr),*) => {
|
||||
{
|
||||
let _cap = headers!(@count $($key),*);
|
||||
let mut _map = headers::HeaderMap::with_capacity(_cap);
|
||||
$(
|
||||
let _ = _map.insert($key, $value);
|
||||
)*
|
||||
_map
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Quirk {
|
||||
pub pattern: Regex,
|
||||
|
|
@ -63,7 +48,6 @@ impl Quirks {
|
|||
}),
|
||||
},
|
||||
];
|
||||
|
||||
Self { quirks }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue