aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/js.rs
diff options
context:
space:
mode:
authorDaniel Robertson <danlrobertson89@gmail.com>2016-02-16 19:38:11 +0000
committerDaniel Robertson <danlrobertson89@gmail.com>2016-02-16 22:40:03 +0000
commit7a35ef15556a42f2d9fab1dd01f40fb313906506 (patch)
treecbb431d15222463fddb910f4699bf54551edfbc8 /components/script/dom/bindings/js.rs
parentf0d4c03bd9c9e181aa1225aec978c2f539e9aeb0 (diff)
downloadservo-7a35ef15556a42f2d9fab1dd01f40fb313906506.tar.gz
servo-7a35ef15556a42f2d9fab1dd01f40fb313906506.zip
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.
Diffstat (limited to 'components/script/dom/bindings/js.rs')
-rw-r--r--components/script/dom/bindings/js.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index 37d673f3c26..1736758e739 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -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