Trait XmlFragment
pub trait XmlFragment: AsRef<Branch> {
// Provided methods
fn first_child(&self) -> Option<XmlOut> { ... }
fn children<'a, T>(&self, txn: &'a T) -> XmlNodes<'a, T> ⓘ
where T: ReadTxn { ... }
fn len<T>(&self, _txn: &T) -> u32
where T: ReadTxn { ... }
fn insert<V>(
&self,
txn: &mut TransactionMut<'_>,
index: u32,
xml_node: V,
) -> <V as Prelim>::Return
where V: XmlPrelim { ... }
fn push_back<V>(
&self,
txn: &mut TransactionMut<'_>,
xml_node: V,
) -> <V as Prelim>::Return
where V: XmlPrelim { ... }
fn push_front<V>(
&self,
txn: &mut TransactionMut<'_>,
xml_node: V,
) -> <V as Prelim>::Return
where V: XmlPrelim { ... }
fn remove(&self, txn: &mut TransactionMut<'_>, index: u32) { ... }
fn remove_range(&self, txn: &mut TransactionMut<'_>, index: u32, len: u32) { ... }
fn get<T>(&self, _txn: &T, index: u32) -> Option<XmlOut>
where T: ReadTxn { ... }
fn successors<'a, T>(&'a self, txn: &'a T) -> TreeWalker<'a, &'a T, T> ⓘ
where T: ReadTxn { ... }
}Provided Methods§
fn first_child(&self) -> Option<XmlOut>
fn children<'a, T>(&self, txn: &'a T) -> XmlNodes<'a, T> ⓘwhere
T: ReadTxn,
fn children<'a, T>(&self, txn: &'a T) -> XmlNodes<'a, T> ⓘwhere
T: ReadTxn,
Returns an iterator over all children of a current XML fragment. It does NOT include nested children of its children - for such cases use Self::successors iterator.
fn len<T>(&self, _txn: &T) -> u32where
T: ReadTxn,
fn len<T>(&self, _txn: &T) -> u32where
T: ReadTxn,
Returns a number of elements stored in current array.
fn insert<V>(
&self,
txn: &mut TransactionMut<'_>,
index: u32,
xml_node: V,
) -> <V as Prelim>::Returnwhere
V: XmlPrelim,
fn insert<V>(
&self,
txn: &mut TransactionMut<'_>,
index: u32,
xml_node: V,
) -> <V as Prelim>::Returnwhere
V: XmlPrelim,
Inserts a value at the given index. Inserting at index 0 is equivalent to prepending
current array with given value, while inserting at array length is equivalent to appending
that value at the end of it.
Using index value that’s higher than current array length results in panic.
fn push_back<V>(
&self,
txn: &mut TransactionMut<'_>,
xml_node: V,
) -> <V as Prelim>::Returnwhere
V: XmlPrelim,
fn push_back<V>(
&self,
txn: &mut TransactionMut<'_>,
xml_node: V,
) -> <V as Prelim>::Returnwhere
V: XmlPrelim,
Inserts given value at the end of the current array.
fn push_front<V>(
&self,
txn: &mut TransactionMut<'_>,
xml_node: V,
) -> <V as Prelim>::Returnwhere
V: XmlPrelim,
fn push_front<V>(
&self,
txn: &mut TransactionMut<'_>,
xml_node: V,
) -> <V as Prelim>::Returnwhere
V: XmlPrelim,
Inserts given value at the beginning of the current array.
fn remove(&self, txn: &mut TransactionMut<'_>, index: u32)
fn remove(&self, txn: &mut TransactionMut<'_>, index: u32)
Removes a single element at provided index.
fn remove_range(&self, txn: &mut TransactionMut<'_>, index: u32, len: u32)
fn remove_range(&self, txn: &mut TransactionMut<'_>, index: u32, len: u32)
Removes a range of elements from current array, starting at given index up until
a particular number described by len has been deleted. This method panics in case when
not all expected elements were removed (due to insufficient number of elements in an array)
or index is outside the bounds of an array.
fn get<T>(&self, _txn: &T, index: u32) -> Option<XmlOut>where
T: ReadTxn,
fn get<T>(&self, _txn: &T, index: u32) -> Option<XmlOut>where
T: ReadTxn,
Retrieves a value stored at a given index. Returns None when provided index was out
of the range of a current array.
fn successors<'a, T>(&'a self, txn: &'a T) -> TreeWalker<'a, &'a T, T> ⓘwhere
T: ReadTxn,
fn successors<'a, T>(&'a self, txn: &'a T) -> TreeWalker<'a, &'a T, T> ⓘwhere
T: ReadTxn,
Returns an iterator that can be used to traverse over the successors of a current XML element. This includes recursive step over children of its children. The recursive iteration is depth-first.
Example:
/* construct node with a shape:
<div>
<p>Hello <b>world</b></p>
again
</div>
*/
use yrs::{Doc, Text, Xml, XmlOut, Transact, XmlFragment, XmlElementPrelim, XmlTextPrelim, GetString};
let doc = Doc::new();
let mut html = doc.get_or_insert_xml_fragment("div");
let mut txn = doc.transact_mut();
let p = html.push_back(&mut txn, XmlElementPrelim::empty("p"));
let txt = p.push_back(&mut txn, XmlTextPrelim::new("Hello "));
let b = p.push_back(&mut txn, XmlElementPrelim::empty("b"));
let txt = b.push_back(&mut txn, XmlTextPrelim::new("world"));
let txt = html.push_back(&mut txn, XmlTextPrelim::new("again"));
let mut result = Vec::new();
for node in html.successors(&txn) {
let value = match node {
XmlOut::Element(elem) => elem.tag().to_string(),
XmlOut::Text(txt) => txt.get_string(&txn),
_ => panic!("shouldn't be the case here")
};
result.push(value);
}
assert_eq!(result, vec![
"p".to_string(),
"Hello ".to_string(),
"b".to_string(),
"world".to_string(),
"again".to_string()
]);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.