From 770e3bab35be88daaf6142249848f114c0d62915 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 22 Sep 2015 07:49:22 -0400 Subject: [PATCH] Add doc-comments about methods that can panic https://github.com/servo/servo/pull/7683/files#r40072222 --- components/script/dom/attr.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index dd7638f08e9..2cd742ee422 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -74,6 +74,11 @@ impl AttrValue { AttrValue::Atom(value) } + /// Assumes the `AttrValue` is a `TokenList` and returns its tokens + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `TokenList` pub fn as_tokens(&self) -> &[Atom] { match *self { AttrValue::TokenList(_, ref tokens) => tokens, @@ -81,6 +86,11 @@ impl AttrValue { } } + /// Assumes the `AttrValue` is an `Atom` and returns its value + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not an `Atom` pub fn as_atom(&self) -> &Atom { match *self { AttrValue::Atom(ref value) => value, @@ -88,6 +98,11 @@ impl AttrValue { } } + /// Assumes the `AttrValue` is a `Length` and returns its value + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `Length` pub fn as_length(&self) -> Option<&Length> { match *self { AttrValue::Length(_, ref length) => length.as_ref(), @@ -98,6 +113,10 @@ impl AttrValue { /// Return the AttrValue as its integer representation, if any. /// This corresponds to attribute values returned as `AttrValue::UInt(_)` /// by `VirtualMethods::parse_plain_attribute()`. + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `UInt` pub fn as_uint(&self) -> u32 { if let AttrValue::UInt(_, value) = *self { value