mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Add some helper methods to util::tree for accessing tree fields (it wasn't possible before due to multiple with_tree_fields implementations)
This commit is contained in:
parent
69ebb04268
commit
d1c6e186bf
1 changed files with 20 additions and 0 deletions
|
@ -34,6 +34,26 @@ pub fn each_child<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T, f: fn(&T) -> bool)
|
|||
}
|
||||
}
|
||||
|
||||
pub fn first_child<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
|
||||
ops.with_tree_fields(node, |tf| tf.first_child)
|
||||
}
|
||||
|
||||
pub fn last_child<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
|
||||
ops.with_tree_fields(node, |tf| tf.last_child)
|
||||
}
|
||||
|
||||
pub fn next_sibling<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
|
||||
ops.with_tree_fields(node, |tf| tf.next_sibling)
|
||||
}
|
||||
|
||||
pub fn prev_sibling<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
|
||||
ops.with_tree_fields(node, |tf| tf.prev_sibling)
|
||||
}
|
||||
|
||||
pub fn parent<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
|
||||
ops.with_tree_fields(node, |tf| tf.parent)
|
||||
}
|
||||
|
||||
pub fn empty<T>() -> Tree<T> {
|
||||
{mut parent: None,
|
||||
mut first_child: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue