use dom::DerefFn;
use std::ops::Deref;
pub use animation::AnimatedSignalVec;
pub trait Mixin {
fn apply(&self, builder: A) -> A;
}
impl Mixin for F where F: Fn(A) -> A {
#[inline]
fn apply(&self, builder: A) -> A {
self(builder)
}
}
// TODO figure out a way to implement this for all of AsRef / Borrow / etc.
// TODO implementations for &String and &mut String
pub trait IntoStr {
type Output: Deref;
fn into_str(self) -> Self::Output;
}
impl IntoStr for String {
type Output = Self;
#[inline]
fn into_str(self) -> Self::Output {
self
}
}
impl<'a> IntoStr for &'a str {
type Output = Self;
#[inline]
fn into_str(self) -> Self::Output {
self
}
}
impl<'a> IntoStr for &'a mut str {
type Output = Self;
#[inline]
fn into_str(self) -> Self::Output {
self
}
}
impl IntoStr for DerefFn where B: Fn(&A) -> &str {
type Output = Self;
#[inline]
fn into_str(self) -> Self::Output {
self
}
}
// TODO figure out a way to implement this for all of AsRef / Borrow / etc.
pub trait IntoOptionStr {
type Output: Deref;
fn into_option_str(self) -> Option;
}
impl IntoOptionStr for A {
type Output = A::Output;
#[inline]
fn into_option_str(self) -> Option {
Some(self.into_str())
}
}
impl IntoOptionStr for Option {
type Output = A::Output;
#[inline]
fn into_option_str(self) -> Option {
self.map(|x| x.into_str())
}
}