nodes/scalar: add data(), data_mut() methods

This commit is contained in:
Paul Stemmet 2022-04-16 14:27:28 +00:00
parent f82dabae9d
commit 12271d1c88
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
1 changed files with 18 additions and 1 deletions

View File

@ -5,7 +5,10 @@
*/
use crate::{
node::nodes::{NodeContext, NodeData, NodeIndex, NodeMark, NodeSpecific, Tag},
node::{
graph::Storage,
nodes::{NodeContext, NodeData, NodeIndex, NodeMark, NodeSpecific, Tag},
},
token::{ScalarStyle, Slice},
};
@ -52,6 +55,20 @@ impl<'de> ScalarNode<'de>
self.parent
}
pub fn data<'a>(&self, g: &'a Storage<'de>) -> ScalarDataRef<'a, 'de>
{
let data = &g.node_data()[self.id];
ScalarDataRef::new(data)
}
pub fn data_mut<'a>(&self, g: &'a mut Storage<'de>) -> ScalarDataMut<'a, 'de>
{
let data = &mut g.node_data_mut()[self.id];
ScalarDataMut::new(data)
}
fn with_parent(id: NodeIndex, scalar: Slice<'de>, parent: Option<NodeIndex>) -> Self
{
Self { parent, id, scalar }