Struct DataStoreNode

Source
pub struct DataStoreNode<'store> { /* private fields */ }
Expand description

Element borrowed from the linked list of nodes that make up a DataStore.

§Lifetime 'store

A DataStoreNode is borrowed from a DataStore, and cannot outlive the DataStore it was borrowed from:

let mut store = DataStore::new();
store.add_named_i64("value", 5);

let node = store.first_node().unwrap();

drop(store);

// Error: `node` cannot outlive `store`.
println!("node name: {:?}", node.name());

Implementations§

Source§

impl<'store> DataStoreNode<'store>

Source

pub fn name(&self) -> Option<String>

Get the name associated with this node, if any.

LibraryLink C Function: DataStoreNode_getName.

Examples found in repository?
examples/tests/test_data_store.rs (line 148)
124fn test_data_store_nodes() {
125    {
126        let mut data = DataStore::new();
127        data.add_i64(5);
128
129        assert_eq!(data.len(), 1);
130
131        let node = data.first_node().expect("got first node");
132
133        let ty: sys::type_t = node.data_type_raw();
134
135        assert_eq!(ty, sys::MType_Integer as i32);
136    }
137
138    // Test DataStoreNode::name() method.
139    {
140        let mut data = DataStore::new();
141        data.add_named_i64("hello", 5);
142
143        assert_eq!(data.len(), 1);
144
145        let node = data.first_node().expect("got first node");
146
147        assert_eq!(node.data_type_raw(), sys::MType_Integer as i32);
148        assert_eq!(node.name(), Some("hello".to_owned()))
149    }
150
151    // Test DataStore::nodes() method and Debug formatting of DataStoreNode.
152    {
153        let mut store = DataStore::new();
154
155        store.add_i64(5);
156        store.add_named_bool("condition", true);
157        store.add_str("Hello, World!");
158
159        let mut nodes = store.nodes();
160
161        assert_eq!(
162            format!("{:?}", nodes.next().unwrap()),
163            r#"DataStoreNode { name: None, value: 5 }"#
164        );
165        assert_eq!(
166            format!("{:?}", nodes.next().unwrap()),
167            r#"DataStoreNode { name: Some("condition"), value: true }"#
168        );
169        assert_eq!(
170            format!("{:?}", nodes.next().unwrap()),
171            r#"DataStoreNode { name: None, value: "Hello, World!" }"#
172        );
173        assert!(nodes.next().is_none());
174    }
175}
Source

pub fn value<'node>(&'node self) -> DataStoreNodeValue<'node>

Get the value stored in this DataStoreNode.

This is a safe wrapper around DataStoreNode::data_raw().

Examples found in repository?
examples/data_store.rs (line 37)
31fn string_join(store: DataStore) -> String {
32    let mut buffer = String::new();
33
34    for node in store.nodes() {
35        // If `node.value()` is a string, append it to our string.
36        // If `node.value()` is NOT a string, silently skip it.
37        if let DataStoreNodeValue::Str(string) = node.value() {
38            buffer.push_str(string);
39        }
40    }
41
42    buffer
43}
Source

pub fn next_node(&self) -> Option<DataStoreNode<'store>>

Get the next node in this linked list of DataStoreNode’s.

LibraryLink C Function: DataStoreNode_getNextNode.

Source

pub fn data_type_raw(&self) -> type_t

LibraryLink C Function: DataStoreNode_getDataType.

Examples found in repository?
examples/tests/test_data_store.rs (line 133)
124fn test_data_store_nodes() {
125    {
126        let mut data = DataStore::new();
127        data.add_i64(5);
128
129        assert_eq!(data.len(), 1);
130
131        let node = data.first_node().expect("got first node");
132
133        let ty: sys::type_t = node.data_type_raw();
134
135        assert_eq!(ty, sys::MType_Integer as i32);
136    }
137
138    // Test DataStoreNode::name() method.
139    {
140        let mut data = DataStore::new();
141        data.add_named_i64("hello", 5);
142
143        assert_eq!(data.len(), 1);
144
145        let node = data.first_node().expect("got first node");
146
147        assert_eq!(node.data_type_raw(), sys::MType_Integer as i32);
148        assert_eq!(node.name(), Some("hello".to_owned()))
149    }
150
151    // Test DataStore::nodes() method and Debug formatting of DataStoreNode.
152    {
153        let mut store = DataStore::new();
154
155        store.add_i64(5);
156        store.add_named_bool("condition", true);
157        store.add_str("Hello, World!");
158
159        let mut nodes = store.nodes();
160
161        assert_eq!(
162            format!("{:?}", nodes.next().unwrap()),
163            r#"DataStoreNode { name: None, value: 5 }"#
164        );
165        assert_eq!(
166            format!("{:?}", nodes.next().unwrap()),
167            r#"DataStoreNode { name: Some("condition"), value: true }"#
168        );
169        assert_eq!(
170            format!("{:?}", nodes.next().unwrap()),
171            r#"DataStoreNode { name: None, value: "Hello, World!" }"#
172        );
173        assert!(nodes.next().is_none());
174    }
175}
Source

pub unsafe fn data_raw(&self) -> &MArgument

LibraryLink C Function: DataStoreNode_getData.

Source

pub unsafe fn try_data_raw<'node>( &'node self, ) -> Result<&'node MArgument, errcode_t>

LibraryLink C Function: DataStoreNode_getData.

Trait Implementations§

Source§

impl<'store> Debug for DataStoreNode<'store>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'store> !Freeze for DataStoreNode<'store>

§

impl<'store> RefUnwindSafe for DataStoreNode<'store>

§

impl<'store> !Send for DataStoreNode<'store>

§

impl<'store> !Sync for DataStoreNode<'store>

§

impl<'store> Unpin for DataStoreNode<'store>

§

impl<'store> UnwindSafe for DataStoreNode<'store>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.