Use Option<T> to return from getters

This removes the cumbersome &mut bool argument and offers overall
a more readable code.
This commit is contained in:
Anthony Ramine 2016-08-29 00:55:29 +02:00
parent 6e1523f4ae
commit 7dfb336be8
22 changed files with 72 additions and 109 deletions

View file

@ -34,10 +34,8 @@ impl TestBindingIterable {
impl TestBindingIterableMethods for TestBindingIterable {
fn Add(&self, v: DOMString) { self.vals.borrow_mut().push(v); }
fn Length(&self) -> u32 { self.vals.borrow().len() as u32 }
fn GetItem(&self, n: u32) -> DOMString { self.vals.borrow().get(n as usize).unwrap().clone() }
fn IndexedGetter(&self, n: u32, found: &mut bool) -> DOMString {
let s = self.GetItem(n);
*found = true;
s
fn GetItem(&self, n: u32) -> DOMString { self.IndexedGetter(n).unwrap_or_default() }
fn IndexedGetter(&self, n: u32) -> Option<DOMString> {
self.vals.borrow().get(n as usize).cloned()
}
}