2018-06-22 13:04:08 -04:00
|
|
|
use dom::DerefFn;
|
|
|
|
use std::ops::Deref;
|
2018-06-13 19:48:41 -04:00
|
|
|
|
2018-03-15 06:54:18 -04:00
|
|
|
pub use animation::AnimatedSignalVec;
|
|
|
|
|
|
|
|
|
2018-04-25 19:01:52 -04:00
|
|
|
pub trait Mixin<A> {
|
|
|
|
fn apply(&self, builder: A) -> A;
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 19:01:52 -04:00
|
|
|
impl<A, F> Mixin<A> for F where F: Fn(A) -> A {
|
2018-02-25 06:58:20 -05:00
|
|
|
#[inline]
|
2018-04-25 19:01:52 -04:00
|
|
|
fn apply(&self, builder: A) -> A {
|
|
|
|
self(builder)
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
// TODO figure out a way to implement this for all of AsRef / Borrow / etc.
|
2018-06-25 21:02:48 -04:00
|
|
|
// TODO implementations for &String and &mut String
|
2018-06-22 13:04:08 -04:00
|
|
|
pub trait IntoStr {
|
|
|
|
type Output: Deref<Target = str>;
|
|
|
|
|
|
|
|
fn into_str(self) -> Self::Output;
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
impl IntoStr for String {
|
|
|
|
type Output = Self;
|
|
|
|
|
2018-02-25 06:58:20 -05:00
|
|
|
#[inline]
|
2018-06-22 13:04:08 -04:00
|
|
|
fn into_str(self) -> Self::Output {
|
|
|
|
self
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
impl<'a> IntoStr for &'a str {
|
|
|
|
type Output = Self;
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
#[inline]
|
2018-06-22 13:04:08 -04:00
|
|
|
fn into_str(self) -> Self::Output {
|
|
|
|
self
|
2018-06-13 19:48:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
impl<'a> IntoStr for &'a mut str {
|
|
|
|
type Output = Self;
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
#[inline]
|
2018-06-22 13:04:08 -04:00
|
|
|
fn into_str(self) -> Self::Output {
|
|
|
|
self
|
2018-06-13 19:48:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
impl<A, B> IntoStr for DerefFn<A, B> where B: Fn(&A) -> &str {
|
|
|
|
type Output = Self;
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
#[inline]
|
2018-06-22 13:04:08 -04:00
|
|
|
fn into_str(self) -> Self::Output {
|
|
|
|
self
|
2018-06-13 19:48:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
// TODO figure out a way to implement this for all of AsRef / Borrow / etc.
|
2018-06-22 13:04:08 -04:00
|
|
|
pub trait IntoOptionStr {
|
|
|
|
type Output: Deref<Target = str>;
|
|
|
|
|
|
|
|
fn into_option_str(self) -> Option<Self::Output>;
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
impl<A: IntoStr> IntoOptionStr for A {
|
|
|
|
type Output = A::Output;
|
|
|
|
|
2018-06-05 11:17:49 -04:00
|
|
|
#[inline]
|
2018-06-22 13:04:08 -04:00
|
|
|
fn into_option_str(self) -> Option<Self::Output> {
|
|
|
|
Some(self.into_str())
|
2018-06-05 11:17:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:04:08 -04:00
|
|
|
impl<A: IntoStr> IntoOptionStr for Option<A> {
|
|
|
|
type Output = A::Output;
|
|
|
|
|
2018-06-05 11:17:49 -04:00
|
|
|
#[inline]
|
2018-06-22 13:04:08 -04:00
|
|
|
fn into_option_str(self) -> Option<Self::Output> {
|
|
|
|
self.map(|x| x.into_str())
|
2018-06-05 11:17:49 -04:00
|
|
|
}
|
|
|
|
}
|