#[macro_export]
macro_rules! map_vec {
($thing:expr, $mapfn:expr) => {
$thing.iter().map($mapfn).collect::<Vec<_>>()
};
}
#[macro_export]
macro_rules! try_map_vec {
($thing:expr, $mapfn:expr) => {
try_iter_map_vec!($thing.iter(), $mapfn);
};
}
#[macro_export]
macro_rules! try_iter_map_vec {
($thing:expr, $mapfn:expr) => {
$thing.map($mapfn).collect::<Result<Vec<_>, _>>()?;
};
}
#[macro_export]
macro_rules! filter_map_vec {
($thing:expr, $mapfn:expr) => {
$thing.iter().filter_map($mapfn).collect::<Vec<_>>();
};
}
#[macro_export]
macro_rules! tee {
($thing:ident, $thing_expr:expr) => {{
$thing_expr;
$thing
}};
}
#[macro_export]
macro_rules! ser_multiread {
($rdr:ident, $($read_call:ident $(($val:expr)),*),*) => {
( $($rdr.$read_call($($val),*)?),* )
}
}
#[macro_export]
macro_rules! ser_multiwrite {
($wrtr:ident, $([ $write_call:ident, $val:expr ]),* ) => {
$($wrtr.$write_call($val)? );*
}
}
macro_rules! hashable_ord {
($hashable:ident) => {
impl Ord for $hashable {
fn cmp(&self, other: &$hashable) -> Ordering {
self.hash().cmp(&other.hash())
}
}
impl PartialOrd for $hashable {
fn partial_cmp(&self, other: &$hashable) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for $hashable {
fn eq(&self, other: &$hashable) -> bool {
self.hash() == other.hash()
}
}
impl Eq for $hashable {}
};
}