Skip to main content

CdsBlock

Struct CdsBlock 

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

Source

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 calling store().
  • If CdsInfo::Restored, the application can immediately call restore() to retrieve the previous state.
§Arguments
  • name: A unique, application-local name for the CDS block.
Source

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.

Source

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.

Source

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.

Source

pub fn handle(&self) -> CdsHandle

Returns the underlying CDS handle.

Source

pub fn get_id_by_name(name: &str) -> Result<CdsHandle>

Finds an existing CDS Block ID by its full name (“AppName.CDSName”).

Trait Implementations§

Source§

impl<T: Debug + Copy + Sized> Debug for CdsBlock<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CdsBlock<T>

§

impl<T> RefUnwindSafe for CdsBlock<T>
where T: RefUnwindSafe,

§

impl<T> Send for CdsBlock<T>
where T: Send,

§

impl<T> Sync for CdsBlock<T>
where T: Sync,

§

impl<T> Unpin for CdsBlock<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for CdsBlock<T>

§

impl<T> UnwindSafe for CdsBlock<T>
where T: UnwindSafe,

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.