2018-06-13 19:48:41 -04:00
|
|
|
use std::sync::Arc;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::borrow::Cow;
|
|
|
|
|
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-04-25 19:01:52 -04:00
|
|
|
pub trait AsStr {
|
|
|
|
fn as_str(&self) -> &str;
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
|
2018-04-25 19:01:52 -04:00
|
|
|
impl AsStr for String {
|
2018-02-25 06:58:20 -05:00
|
|
|
#[inline]
|
2018-04-25 19:01:52 -04:00
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
self.as_str()
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
impl<A: AsStr> AsStr for Box<A> {
|
|
|
|
#[inline]
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
(**self).as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A: AsStr> AsStr for Arc<A> {
|
|
|
|
#[inline]
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
(**self).as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A: AsStr> AsStr for Rc<A> {
|
|
|
|
#[inline]
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
(**self).as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, A: AsStr + Clone> AsStr for Cow<'a, A> {
|
|
|
|
#[inline]
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
(**self).as_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsStr for str {
|
|
|
|
#[inline]
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 19:01:52 -04:00
|
|
|
impl<'a> AsStr for &'a str {
|
2018-02-25 06:58:20 -05:00
|
|
|
#[inline]
|
2018-04-25 19:01:52 -04:00
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
self
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
impl<'a> AsStr for &'a mut str {
|
|
|
|
#[inline]
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-04-25 19:01:52 -04:00
|
|
|
pub trait AsOptionStr {
|
|
|
|
fn as_option_str(&self) -> Option<&str>;
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
impl<A: AsStr> AsOptionStr for A {
|
2018-06-05 11:17:49 -04:00
|
|
|
#[inline]
|
|
|
|
fn as_option_str(&self) -> Option<&str> {
|
2018-06-13 19:48:41 -04:00
|
|
|
Some(self.as_str())
|
2018-06-05 11:17:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
impl<A: AsStr> AsOptionStr for Option<A> {
|
2018-06-05 11:17:49 -04:00
|
|
|
#[inline]
|
|
|
|
fn as_option_str(&self) -> Option<&str> {
|
2018-06-13 19:48:41 -04:00
|
|
|
self.as_ref().map(|x| x.as_str())
|
2018-06-05 11:17:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
/*impl<A: AsStr> AsOptionStr for Box<Option<A>> {
|
2018-02-25 06:58:20 -05:00
|
|
|
#[inline]
|
2018-04-25 19:01:52 -04:00
|
|
|
fn as_option_str(&self) -> Option<&str> {
|
2018-06-13 19:48:41 -04:00
|
|
|
(**self).as_option_str()
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 19:48:41 -04:00
|
|
|
impl<A: AsStr> AsOptionStr for Arc<Option<A>> {
|
2018-03-01 08:39:58 -05:00
|
|
|
#[inline]
|
2018-04-25 19:01:52 -04:00
|
|
|
fn as_option_str(&self) -> Option<&str> {
|
2018-06-13 19:48:41 -04:00
|
|
|
(**self).as_option_str()
|
2018-03-01 08:39:58 -05:00
|
|
|
}
|
2018-02-25 06:58:20 -05:00
|
|
|
}
|
2018-06-13 19:48:41 -04:00
|
|
|
|
|
|
|
impl<A: AsStr> AsOptionStr for Rc<Option<A>> {
|
|
|
|
#[inline]
|
|
|
|
fn as_option_str(&self) -> Option<&str> {
|
|
|
|
(**self).as_option_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, A: AsStr + Clone> AsOptionStr for Cow<'a, Option<A>> {
|
|
|
|
#[inline]
|
|
|
|
fn as_option_str(&self) -> Option<&str> {
|
|
|
|
(**self).as_option_str()
|
|
|
|
}
|
|
|
|
}*/
|