mirror of
https://github.com/openharmony/third_party_rust_bytes.git
synced 2026-07-21 04:15:24 -04:00
Introduce Bytes::to_mut (#188)
This commit is contained in:
committed by
Carl Lerche
parent
808f2fb8ec
commit
fecf36f1c7
@@ -763,6 +763,17 @@ impl Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
/// Acquires a mutable reference to the owned form of the data.
|
||||
///
|
||||
/// Clones the data if it is not already owned.
|
||||
pub fn to_mut(&mut self) -> &mut BytesMut {
|
||||
if !self.inner.is_mut_safe() {
|
||||
let new = Bytes::from(&self[..]);
|
||||
*self = new;
|
||||
}
|
||||
unsafe { &mut *(self as *mut Bytes as *mut BytesMut) }
|
||||
}
|
||||
|
||||
/// Appends given bytes to this object.
|
||||
///
|
||||
/// If this `Bytes` object has not enough capacity, it is resized first.
|
||||
|
||||
Reference in New Issue
Block a user