Implement RootedReference<T> for Option<JS<T>>

An implementation of RootedReference for Option<JS<T>> based off of
other implementations of RootedReference for Option wrapped types.
This commit is contained in:
Daniel Robertson 2016-02-16 19:38:11 +00:00
parent f0d4c03bd9
commit 7a35ef1555
3 changed files with 10 additions and 3 deletions

View file

@ -444,6 +444,13 @@ impl<T: Reflectable> RootedReference<T> for Option<Root<T>> {
}
}
/// Get an `Option<&T> out of an `Option<JS<T>>`
impl<T: Reflectable> RootedReference<T> for Option<JS<T>> {
fn r(&self) -> Option<&T> {
self.as_ref().map(|inner| &**inner)
}
}
/// Get an `Option<Option<&T>>` out of an `Option<Option<Root<T>>>`
pub trait OptionalRootedReference<T> {
/// Obtain a safe optional optional reference to the wrapped JS owned-value