Skip to main content

AsSyncStr

Trait AsSyncStr 

Source
pub trait AsSyncStr: Sync + Send {
    // Required method
    fn as_str(&self) -> &str;
}
Expand description

Trait for types that can provide a string reference in a thread-safe manner.

This trait extends the basic string reference functionality with thread-safety guarantees by requiring both Sync and Send bounds. It’s useful for types that need to provide string data across thread boundaries in a concurrent environment.

§Thread Safety

Implementors must be both Sync (safe to share references across threads) and Send (safe to transfer ownership across threads).

§Examples

use osal_rs::utils::AsSyncStr;
 
struct ThreadSafeName {
    name: &'static str,
}
 
impl AsSyncStr for ThreadSafeName {
    fn as_str(&self) -> &str {
        self.name
    }
}
 
// Can be safely shared across threads
fn use_in_thread(item: &dyn AsSyncStr) {
    println!("Name: {}", item.as_str());
}

Required Methods§

Source

fn as_str(&self) -> &str

Returns a string slice reference.

This method provides access to the underlying string data in a way that is safe to use across thread boundaries.

§Returns

A reference to a string slice with lifetime tied to self.

Trait Implementations§

Source§

impl Debug for dyn AsSyncStr + '_

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for dyn AsSyncStr + '_

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for dyn AsSyncStr + '_

Source§

impl PartialEq for dyn AsSyncStr + '_

Source§

fn eq(&self, other: &(dyn AsSyncStr + '_)) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const SIZE: usize> AsSyncStr for Bytes<SIZE>