@@ -270,10 +270,18 @@ impl Tree {
273+ /// Get reference to a [`view`] by index.
276+ /// Panics if `index` is not in self.nodes, or if the node's content is not [`Content::View`] . This can be checked with [`contains`]
273 pub fn get(&self, index: ViewId) -> &View {
277 pub fn get(&self, index: ViewId) -> &View {
274 self.try_get(index).unwrap()
278 self.try_get(index).unwrap()
281+ /// Try to get reference to a [`view`] by index. Returns `None` if node content is not a [`Content::View`]
284+ /// Panics if `index` is not in self.nodes. This can be checked with [`Self::contains`]
277 pub fn try_get(&self, index: ViewId) -> Option<&View> {
285 pub fn try_get(&self, index: ViewId) -> Option<&View> {
278 match &self.nodes[index] {
286 match &self.nodes[index] {
@@ -284,6 +292,10 @@ impl Tree {
295+ /// Get a mutable reference to a [`view`] by index.
298+ /// Panics if `index` is not in self.nodes, or if the node's content is not [`Content::View`] . This can be checked with [`Self::contains`]
287 pub fn get_mut(&mut self, index: ViewId) -> &mut View {
299 pub fn get_mut(&mut self, index: ViewId) -> &mut View {
288 match &mut self.nodes[index] {
300 match &mut self.nodes[index] {
@@ -294,6 +306,11 @@ impl Tree {
309+ /// Check if tree contains a [`Node`] with a given index.
310+ pub fn contains(&self, index: ViewId) -> bool {
311+ self.nodes.contains_key(index)
297 pub fn is_empty(&self) -> bool {
314 pub fn is_empty(&self) -> bool {
298 match &self.nodes[self.root] {
315 match &self.nodes[self.root] {