pub struct CdsBlock<T: Copy + Sized> { /* private fields */ }Expand description
A handle to a block of data in the cFE Critical Data Store.
This struct is generic over the data type T to be stored. The underlying
CDS block is registered when new is called and persists for the life of the
cFE instance (across resets).
The type T must be Copy and Sized, as the underlying CFE API performs
a raw byte copy of the data.
Implementations§
Source§impl<T: Copy + Sized> CdsBlock<T>
impl<T: Copy + Sized> CdsBlock<T>
Sourcepub fn new(name: &str) -> Result<(Self, CdsInfo)>
pub fn new(name: &str) -> Result<(Self, CdsInfo)>
Registers a new CDS block with the given name or retrieves an existing one.
This function will attempt to create a CDS block of size_of::<T>().
The block contents are NOT cleared or initialized on creation.
If a block with this name already existed but with a different size,
it is replaced. The new block contains uninitialized data and
CdsInfo::Created is returned (not Restored).
§Return Value
On success, returns Ok((CdsBlock, CdsInfo)). The CdsInfo indicates
whether the block was newly created or was restored from a previous run.
- If
CdsInfo::Created, the application is responsible for initializing the data by callingstore(). - If
CdsInfo::Restored, the application can immediately callrestore()to retrieve the previous state.
§Arguments
name: A unique, application-local name for the CDS block.
Sourcepub fn store(&self, data: &T) -> Result<()>
pub fn store(&self, data: &T) -> Result<()>
Stores a copy of data into the CDS block.
This should be called after new reports CdsInfo::Created, or any
time the application wishes to update the persistent state.
Sourcepub fn restore_or_default(name: &str) -> Result<(Self, T)>where
T: Default,
pub fn restore_or_default(name: &str) -> Result<(Self, T)>where
T: Default,
Creates a CDS block and restores previous state, or uses
T::default() if the block is new or corrupted.
Sourcepub fn restore(&self) -> Result<T>
pub fn restore(&self) -> Result<T>
Restores the contents of the CDS block into a new instance of T.
This will perform a raw byte copy from the CDS into the returned struct.
It is safe because T is constrained to be Copy.
Returns Err if the data in the CDS has been corrupted
(e.g. CRC mismatch). The corrupted data is not returned.
Sourcepub fn get_id_by_name(name: &str) -> Result<CdsHandle>
pub fn get_id_by_name(name: &str) -> Result<CdsHandle>
Finds an existing CDS Block ID by its full name (“AppName.CDSName”).