pub struct SpudObjectSync { /* private fields */ }Expand description
Represents a SPUD object, which is a collection of fields and values. It allows adding values to fields and manages the internal data structure for SPUD encoding.
Implementations§
Source§impl SpudObjectSync
impl SpudObjectSync
Sourcepub fn add_value<T: SpudTypesExt>(
&self,
field_name: &str,
value: T,
) -> Result<&Self, SpudError>
pub fn add_value<T: SpudTypesExt>( &self, field_name: &str, value: T, ) -> Result<&Self, SpudError>
Adds a value to the object with the specified field name.
§Arguments
field_name- The name of the field to which the value will be added.value- The value to be added, which must implement theSpudTypesExttrait.
§Examples
use spud_rs::{SpudBuilder, SpudObjectSync, types::SpudString};
let builder = SpudBuilder::new();
builder.object(|obj| {
obj.add_value("example_field", SpudString::from("example_value"));
Ok(())
});
// The object now contains the field "example_field" with the value "example_value".§Returns
A mutable reference to the SpudObjectSync, allowing for method chaining.
§Errors
If the field name is too long (greater than 255 characters) or if there is an error generating a unique ID, this method will return an error.
§Panics
Panics if the Mutex cannot be locked, which is unlikely but can happen in case of a deadlock or other synchronization issues.
Sourcepub fn object<F>(&self, field_name: &str, f: F) -> Result<(), SpudError>
pub fn object<F>(&self, field_name: &str, f: F) -> Result<(), SpudError>
Creates a new SpudObjectSync instance associated with this Object.
§Errors
Returns an error if the object cannot be created, typically due to internal issues with the builder’s state.
§Panics
Panics if the Mutex cannot be locked, which is unlikely but can happen in case of a deadlock or other synchronization issues.