yew_alt_html/
util.rs

1//
2// FilterResultOrDefault
3//
4
5pub trait FilterResultOrDefault<T, E: Default> {
6    fn filter_or_default(self, filter: impl FnOnce(&T) -> bool) -> Self;
7}
8
9impl<T, E: Default> FilterResultOrDefault<T, E> for Result<T, E> {
10    fn filter_or_default(self, filter: impl FnOnce(&T) -> bool) -> Self {
11        match self {
12            Ok(v) if filter(&v) => Ok(v),
13            Ok(_) => Err(E::default()),
14            Err(e) => Err(e),
15        }
16    }
17}
18
19//
20// Append
21//
22
23pub trait ImplIntoExt<T> {
24    fn append_from(&mut self, values: impl IntoIterator<Item = impl Into<T>>);
25
26    fn push_from(&mut self, value: impl Into<T>);
27}
28
29impl<T> ImplIntoExt<T> for Vec<T> {
30    fn append_from(&mut self, values: impl IntoIterator<Item = impl Into<T>>) {
31        self.append(
32            &mut values
33                .into_iter()
34                .map(Into::<T>::into)
35                .collect(),
36        )
37    }
38
39    fn push_from(&mut self, value: impl Into<T>) { self.push(value.into()) }
40}
41
42//
43// MatchOpt
44//
45
46pub trait MatchOpt<T> {
47    fn match_opt(self) -> Option<T>;
48}