pub struct RwBuffer(/* private fields */);Expand description
A base instance which holds the leaked pointer to RwBufferInner.
This instance can provide either an exclusive write access or multiple read access, but not at the same time. Can be used to store the instance. This instance is Send and Sync because the insternals are guarded by ordered atomic operations.
Implementations§
Source§impl RwBuffer
impl RwBuffer
Sourcepub fn is_free(&self) -> bool
pub fn is_free(&self) -> bool
Checks if this instance satisfies the following conditions:
-
No exclusive write access
-
No read access
-
There is only one base reference.
But since check everything may have been already changed.
§Returns
-
trueif instance satisfies the conditions above.
-
falseif does not satisfy the conditions above.
Sourcepub fn write(&self) -> RwBufferRes<WBuffer>
pub fn write(&self) -> RwBufferRes<WBuffer>
Attemts to make an exclusive (write) access to the buffer.
Would block for short period of time and return error.
§Returns
A Result in form of RwBufferRes is returned with:
-
Result::Ok with the WBuffer instance
-
Result::Err may be returned a RwBufferError::WriteTryAgianLater in case if the there is/are an active
readreferences or acquite exc. lock failed.
Sourcepub async fn write_async(&self) -> RwBufferRes<WBuffer>
pub async fn write_async(&self) -> RwBufferRes<WBuffer>
Attempts to gain an exclusive access in async way.
§Return
Return the same result as RwBuffer::write.
Sourcepub fn read(&self) -> RwBufferRes<RBuffer>
pub fn read(&self) -> RwBufferRes<RBuffer>
Attemts to make a shared (read) access to the buffer.
Would block for short period of time and return error.
§Returns
A Result in form of RwBufferRes is returned with:
-
Result::Ok with the RBuffer instance
-
Result::Err with error type is returned:
-
RwBufferError::TooManyRead is returned when the soft limit of references was reached.
-
RwBufferError::ReadTryAgianLater is returned if there is an active exclusive access.
Sourcepub async fn read_async(&self) -> RwBufferRes<RBuffer>
pub async fn read_async(&self) -> RwBufferRes<RBuffer>
Trait Implementations§
Source§impl TryClone for RwBuffer
impl TryClone for RwBuffer
Source§fn try_clone(&self) -> Result<Self, Self::Error>
fn try_clone(&self) -> Result<Self, Self::Error>
Attempts to clone the RwBuffer incrementing the base reference.
§Returns
Returns the new Result where on success a clone of RBuffer instance is returned, otherwise the:
-
RwBufferError::BaseTryAgainLater - is returned if it failed to acquire the base clone in reasonable time.
-
RwBufferError::TooManyBase - is returned if limit was reached.