File: traits.rs

package info (click to toggle)
gir-rust-code-generator 0.21.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,520 kB
  • sloc: python: 191; makefile: 27
file content (32 lines) | stat: -rw-r--r-- 702 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub use crate::config::{matchable::Matchable, parameter_matchable::ParameterMatchable};

pub trait IntoString {
    fn into_string(self) -> String;
}

pub trait MapAny<T> {
    fn map_any<F: FnOnce(T) -> T>(self, op: F) -> Self;
}

impl<T> MapAny<T> for Result<T, T> {
    fn map_any<F: FnOnce(T) -> T>(self, op: F) -> Self {
        match self {
            Ok(x) => Ok(op(x)),
            Err(x) => Err(op(x)),
        }
    }
}

pub trait MaybeRef<T> {
    fn maybe_ref(&self) -> Option<&T>;
    fn to_ref(&self) -> &T;
}

pub trait MaybeRefAs {
    fn maybe_ref_as<T>(&self) -> Option<&T>
    where
        Self: MaybeRef<T>;
    fn to_ref_as<T>(&self) -> &T
    where
        Self: MaybeRef<T>;
}