Struct Record

Source
pub struct Record(/* private fields */);
Expand description

A container for storing key-value pairs of various data types.

This structure provides a flexible way to store and retrieve different types of data using string keys. It supports merging records and provides type-safe access to stored values.

Implementations§

Source§

impl Record

Source

pub fn empty() -> Self

Creates an empty record.

§Returns

A new empty record

Source

pub fn from_scalar(name: impl Into<String>, value: f32) -> Self

Creates a record containing a single scalar value.

§Arguments
  • name - The key for the scalar value
  • value - The scalar value to store
§Returns

A new record containing the scalar value

Source

pub fn from_slice<K: Into<String> + Clone>(s: &[(K, RecordValue)]) -> Self

Creates a record from a slice of key-value pairs.

§Arguments
  • s - A slice of tuples containing keys and values
§Returns

A new record containing all the key-value pairs

Source

pub fn keys(&self) -> Keys<'_, String, RecordValue>

Returns an iterator over the keys in the record.

§Returns

An iterator over the record’s keys

Source

pub fn insert(&mut self, k: impl Into<String>, v: RecordValue)

Inserts a key-value pair into the record.

§Arguments
  • k - The key to insert
  • v - The value to insert
Source

pub fn iter(&self) -> Iter<'_, String, RecordValue>

Returns an iterator over the key-value pairs in the record.

§Returns

An iterator over the record’s key-value pairs

Source

pub fn into_iter_in_record(self) -> IntoIter<String, RecordValue>

Returns an iterator that consumes the record.

§Returns

An iterator that takes ownership of the record

Source

pub fn get(&self, k: &str) -> Option<&RecordValue>

Gets a reference to the value associated with the given key.

§Arguments
  • k - The key to look up
§Returns

A reference to the value if the key exists, None otherwise

Source

pub fn merge(self, record: Record) -> Self

Merges two records, consuming both.

If both records contain the same key, the value from the second record will overwrite the value from the first record.

§Arguments
  • record - The record to merge with
§Returns

A new record containing all key-value pairs from both records

Source

pub fn merge_inplace(&mut self, record: Record)

Merges another record into this one in place.

If both records contain the same key, the value from the second record will overwrite the value from this record.

§Arguments
  • record - The record to merge with
Source

pub fn get_scalar(&self, k: &str) -> Result<f32, LrrError>

Gets a scalar value from the record.

§Arguments
  • k - The key of the scalar value
§Returns

The scalar value if it exists and is of the correct type

§Errors

Returns an error if:

  • The key does not exist
  • The value is not a scalar
Source

pub fn get_array1(&self, k: &str) -> Result<Vec<f32>, LrrError>

Gets a 1-dimensional array from the record.

§Arguments
  • k - The key of the array
§Returns

The array if it exists and is of the correct type

§Errors

Returns an error if:

  • The key does not exist
  • The value is not a 1-dimensional array
Source

pub fn get_array2(&self, k: &str) -> Result<(Vec<f32>, [usize; 2]), LrrError>

Gets a 2-dimensional array from the record.

§Arguments
  • k - The key of the array
§Returns

A tuple containing the array data and its shape

§Errors

Returns an error if:

  • The key does not exist
  • The value is not a 2-dimensional array
Source

pub fn get_array3(&self, k: &str) -> Result<(Vec<f32>, [usize; 3]), LrrError>

Gets a 3-dimensional array from the record.

§Arguments
  • k - The key of the array
§Returns

A tuple containing the array data and its shape

§Errors

Returns an error if:

  • The key does not exist
  • The value is not a 3-dimensional array
Source

pub fn get_string(&self, k: &str) -> Result<String, LrrError>

Gets a string value from the record.

§Arguments
  • k - The key of the string
§Returns

The string if it exists and is of the correct type

§Errors

Returns an error if:

  • The key does not exist
  • The value is not a string
Source

pub fn is_empty(&self) -> bool

Checks if the record is empty.

§Returns

true if the record contains no key-value pairs

Source

pub fn get_scalar_without_key(&self) -> Option<f32>

Gets a scalar value from the record without specifying a key.

This method is useful when the record contains only one scalar value.

§Returns

The scalar value if it exists and is the only value in the record

Trait Implementations§

Source§

impl Debug for Record

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Record

§

impl RefUnwindSafe for Record

§

impl Send for Record

§

impl Sync for Record

§

impl Unpin for Record

§

impl UnwindSafe for Record

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V