Skip to content

Commit

Permalink
feat(gstd): add From & Default implementation for sync primitives (#3429
Browse files Browse the repository at this point in the history
)
  • Loading branch information
NikVolf authored Oct 20, 2023
1 parent ece52b4 commit 684cc76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gstd/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ pub struct Mutex<T> {
queue: AccessQueue,
}

impl<T> From<T> for Mutex<T> {
fn from(t: T) -> Self {
Mutex::new(t)
}
}

impl<T: Default> Default for Mutex<T> {
fn default() -> Self {
<T as Default>::default().into()
}
}

impl<T> Mutex<T> {
/// Create a new mutex in an unlocked state ready for use.
pub const fn new(t: T) -> Mutex<T> {
Expand Down
12 changes: 12 additions & 0 deletions gstd/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ pub struct RwLock<T> {
queue: AccessQueue,
}

impl<T> From<T> for RwLock<T> {
fn from(t: T) -> Self {
RwLock::new(t)
}
}

impl<T: Default> Default for RwLock<T> {
fn default() -> Self {
<T as Default>::default().into()
}
}

impl<T> RwLock<T> {
/// Limit of readers for `RwLock`
pub const READERS_LIMIT: ReadersCount = READERS_LIMIT;
Expand Down

0 comments on commit 684cc76

Please sign in to comment.