diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/bstr-0.2.17/src/bstr.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bstr-0.2.17/src/bstr.rs')
-rw-r--r-- | vendor/bstr-0.2.17/src/bstr.rs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/vendor/bstr-0.2.17/src/bstr.rs b/vendor/bstr-0.2.17/src/bstr.rs deleted file mode 100644 index 1e3c91b9a..000000000 --- a/vendor/bstr-0.2.17/src/bstr.rs +++ /dev/null @@ -1,74 +0,0 @@ -use core::mem; - -/// A wrapper for `&[u8]` that provides convenient string oriented trait impls. -/// -/// If you need ownership or a growable byte string buffer, then use -/// [`BString`](struct.BString.html). -/// -/// Using a `&BStr` is just like using a `&[u8]`, since `BStr` -/// implements `Deref` to `[u8]`. So all methods available on `[u8]` -/// are also available on `BStr`. -/// -/// # Representation -/// -/// A `&BStr` has the same representation as a `&str`. That is, a `&BStr` is -/// a fat pointer which consists of a pointer to some bytes and a length. -/// -/// # Trait implementations -/// -/// The `BStr` type has a number of trait implementations, and in particular, -/// defines equality and ordinal comparisons between `&BStr`, `&str` and -/// `&[u8]` for convenience. -/// -/// The `Debug` implementation for `BStr` shows its bytes as a normal string. -/// For invalid UTF-8, hex escape sequences are used. -/// -/// The `Display` implementation behaves as if `BStr` were first lossily -/// converted to a `str`. Invalid UTF-8 bytes are substituted with the Unicode -/// replacement codepoint, which looks like this: �. -#[derive(Hash)] -#[repr(transparent)] -pub struct BStr { - pub(crate) bytes: [u8], -} - -impl BStr { - #[inline] - pub(crate) fn new<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &BStr { - BStr::from_bytes(bytes.as_ref()) - } - - #[inline] - pub(crate) fn new_mut<B: ?Sized + AsMut<[u8]>>( - bytes: &mut B, - ) -> &mut BStr { - BStr::from_bytes_mut(bytes.as_mut()) - } - - #[inline] - pub(crate) fn from_bytes(slice: &[u8]) -> &BStr { - unsafe { mem::transmute(slice) } - } - - #[inline] - pub(crate) fn from_bytes_mut(slice: &mut [u8]) -> &mut BStr { - unsafe { mem::transmute(slice) } - } - - #[inline] - #[cfg(feature = "std")] - pub(crate) fn from_boxed_bytes(slice: Box<[u8]>) -> Box<BStr> { - unsafe { Box::from_raw(Box::into_raw(slice) as _) } - } - - #[inline] - #[cfg(feature = "std")] - pub(crate) fn into_boxed_bytes(slice: Box<BStr>) -> Box<[u8]> { - unsafe { Box::from_raw(Box::into_raw(slice) as _) } - } - - #[inline] - pub(crate) fn as_bytes(&self) -> &[u8] { - &self.bytes - } -} |