rust-dominator/src/traits.rs

52 lines
829 B
Rust
Raw Normal View History

2018-03-15 06:54:18 -04:00
pub use animation::AnimatedSignalVec;
pub trait Mixin<A> {
fn apply(&self, builder: A) -> A;
2018-02-25 06:58:20 -05:00
}
impl<A, F> Mixin<A> for F where F: Fn(A) -> A {
2018-02-25 06:58:20 -05:00
#[inline]
fn apply(&self, builder: A) -> A {
self(builder)
2018-02-25 06:58:20 -05:00
}
}
pub trait AsStr {
fn as_str(&self) -> &str;
2018-02-25 06:58:20 -05:00
}
impl AsStr for String {
2018-02-25 06:58:20 -05:00
#[inline]
fn as_str(&self) -> &str {
self.as_str()
2018-02-25 06:58:20 -05:00
}
}
impl<'a> AsStr for &'a str {
2018-02-25 06:58:20 -05:00
#[inline]
fn as_str(&self) -> &str {
self
2018-02-25 06:58:20 -05:00
}
}
pub trait AsOptionStr {
fn as_option_str(&self) -> Option<&str>;
2018-02-25 06:58:20 -05:00
}
impl AsOptionStr for Option<String> {
2018-02-25 06:58:20 -05:00
#[inline]
fn as_option_str(&self) -> Option<&str> {
self.as_ref().map(|x| x.as_str())
2018-02-25 06:58:20 -05:00
}
}
impl<'a> AsOptionStr for Option<&'a str> {
#[inline]
fn as_option_str(&self) -> Option<&str> {
*self
}
2018-02-25 06:58:20 -05:00
}