From 684cc76a57c9cb5a7ee06d396934826273e31611 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 20 Oct 2023 18:28:55 +0300 Subject: [PATCH] feat(gstd): add From & Default implementation for sync primitives (#3429) --- gstd/src/sync/mutex.rs | 12 ++++++++++++ gstd/src/sync/rwlock.rs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gstd/src/sync/mutex.rs b/gstd/src/sync/mutex.rs index f978cc21d7a..49de9615610 100644 --- a/gstd/src/sync/mutex.rs +++ b/gstd/src/sync/mutex.rs @@ -102,6 +102,18 @@ pub struct Mutex { queue: AccessQueue, } +impl From for Mutex { + fn from(t: T) -> Self { + Mutex::new(t) + } +} + +impl Default for Mutex { + fn default() -> Self { + ::default().into() + } +} + impl Mutex { /// Create a new mutex in an unlocked state ready for use. pub const fn new(t: T) -> Mutex { diff --git a/gstd/src/sync/rwlock.rs b/gstd/src/sync/rwlock.rs index f2f701954ec..d1ac8638261 100644 --- a/gstd/src/sync/rwlock.rs +++ b/gstd/src/sync/rwlock.rs @@ -115,6 +115,18 @@ pub struct RwLock { queue: AccessQueue, } +impl From for RwLock { + fn from(t: T) -> Self { + RwLock::new(t) + } +} + +impl Default for RwLock { + fn default() -> Self { + ::default().into() + } +} + impl RwLock { /// Limit of readers for `RwLock` pub const READERS_LIMIT: ReadersCount = READERS_LIMIT;