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());
}