use alloc::borrow::Cow; use alloc::string::String; use alloc::vec::Vec; use core::fmt;
/// A byte slice. /// /// Uses copy-on-write to avoid unnecessary allocations. The bytes can be /// accessed as a slice using the `Deref` trait, or as a mutable `Vec` using the /// `to_mut` method. /// /// Provides a `Debug` implementation that shows the first 8 bytes and the length. #[derive(Default, Clone, PartialEq, Eq)] pubstruct Bytes<'a>(Cow<'a, [u8]>);
impl<'a> Bytes<'a> { /// Acquire a mutable reference to the bytes. /// /// Clones the bytes if they are shared. pubfn to_mut(&mutself) -> &mut Vec<u8> { self.0.to_mut()
}
/// Get the bytes as a slice. pubfn as_slice(&self) -> &[u8] { self.0.as_ref()
}
}
impl<'a> core::ops::Deref for Bytes<'a> { type Target = [u8]; fn deref(&self) -> &[u8] { self.0.deref()
}
}
/// A byte slice that is a string of an unknown encoding. /// /// Uses copy-on-write to avoid unnecessary allocations. The bytes can be /// accessed as a slice using the `Deref` trait, or as a mutable `Vec` using the /// `to_mut` method. /// /// Provides a `Debug` implementation that interprets the bytes as UTF-8. #[derive(Default, Clone, PartialEq, Eq, Hash)] pubstruct ByteString<'a>(Cow<'a, [u8]>);
impl<'a> ByteString<'a> { /// Acquire a mutable reference to the bytes. /// /// Clones the bytes if they are shared. pubfn to_mut(&mutself) -> &mut Vec<u8> { self.0.to_mut()
}
/// Get the bytes as a slice. pubfn as_slice(&self) -> &[u8] { self.0.as_ref()
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.