mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +01:00
Implement OwningHandle in style.
I've also PR-ed this against upstream [1], but I don't want to block on that in case it takes a while to be merged / published. [1] https://github.com/Kimundi/owning-ref-rs/pull/15
This commit is contained in:
parent
3f31ffad2f
commit
d73047584c
9 changed files with 134 additions and 9 deletions
|
@ -13,6 +13,7 @@ doctest = false
|
|||
app_units = "0.3"
|
||||
cssparser = {version = "0.7", features = ["heap_size"]}
|
||||
euclid = "0.10.1"
|
||||
owning_ref = "0.2.2"
|
||||
parking_lot = "0.3"
|
||||
rustc-serialize = "0.3"
|
||||
selectors = "0.13"
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
extern crate app_units;
|
||||
extern crate cssparser;
|
||||
extern crate euclid;
|
||||
extern crate owning_ref;
|
||||
extern crate parking_lot;
|
||||
extern crate rustc_serialize;
|
||||
extern crate selectors;
|
||||
|
@ -22,6 +23,7 @@ mod attr;
|
|||
mod cache;
|
||||
mod logical_geometry;
|
||||
mod media_queries;
|
||||
mod owning_handle;
|
||||
mod parsing;
|
||||
mod properties;
|
||||
mod selector_matching;
|
||||
|
|
34
tests/unit/style/owning_handle.rs
Normal file
34
tests/unit/style/owning_handle.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use owning_ref::RcRef;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use style::owning_handle::OwningHandle;
|
||||
|
||||
#[test]
|
||||
fn owning_handle() {
|
||||
use std::cell::RefCell;
|
||||
let cell = Rc::new(RefCell::new(2));
|
||||
let cell_ref = RcRef::new(cell);
|
||||
let mut handle = OwningHandle::new(cell_ref, |x| unsafe { x.as_ref() }.unwrap().borrow_mut());
|
||||
assert_eq!(*handle, 2);
|
||||
*handle = 3;
|
||||
assert_eq!(*handle, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested() {
|
||||
let result = {
|
||||
let complex = Rc::new(RefCell::new(Arc::new(RwLock::new("someString"))));
|
||||
let curr = RcRef::new(complex);
|
||||
let curr = OwningHandle::new(curr, |x| unsafe { x.as_ref() }.unwrap().borrow_mut());
|
||||
let mut curr = OwningHandle::new(curr, |x| unsafe { x.as_ref() }.unwrap().try_write().unwrap());
|
||||
assert_eq!(*curr, "someString");
|
||||
*curr = "someOtherString";
|
||||
curr
|
||||
};
|
||||
assert_eq!(*result, "someOtherString");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue