From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/bstr/src/impls.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'vendor/bstr/src/impls.rs') diff --git a/vendor/bstr/src/impls.rs b/vendor/bstr/src/impls.rs index e017cf1ac..861ca5376 100644 --- a/vendor/bstr/src/impls.rs +++ b/vendor/bstr/src/impls.rs @@ -66,7 +66,7 @@ mod bstring { }; use alloc::{ - borrow::{Borrow, Cow, ToOwned}, + borrow::{Borrow, BorrowMut, Cow, ToOwned}, string::String, vec, vec::Vec, @@ -134,6 +134,13 @@ mod bstring { } } + impl Borrow<[u8]> for BString { + #[inline] + fn borrow(&self) -> &[u8] { + self.as_bytes() + } + } + impl Borrow for BString { #[inline] fn borrow(&self) -> &BStr { @@ -141,6 +148,41 @@ mod bstring { } } + impl Borrow for Vec { + #[inline] + fn borrow(&self) -> &BStr { + self.as_slice().as_bstr() + } + } + + impl Borrow for String { + #[inline] + fn borrow(&self) -> &BStr { + self.as_bytes().as_bstr() + } + } + + impl BorrowMut<[u8]> for BString { + #[inline] + fn borrow_mut(&mut self) -> &mut [u8] { + self.as_bytes_mut() + } + } + + impl BorrowMut for BString { + #[inline] + fn borrow_mut(&mut self) -> &mut BStr { + self.as_mut_bstr() + } + } + + impl BorrowMut for Vec { + #[inline] + fn borrow_mut(&mut self) -> &mut BStr { + BStr::new_mut(self.as_mut_slice()) + } + } + impl ToOwned for BStr { type Owned = BString; @@ -338,7 +380,12 @@ mod bstring { } mod bstr { - use core::{cmp::Ordering, convert::TryFrom, fmt, ops}; + use core::{ + borrow::{Borrow, BorrowMut}, + cmp::Ordering, + convert::TryFrom, + fmt, ops, + }; #[cfg(feature = "alloc")] use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec}; @@ -612,6 +659,41 @@ mod bstr { } } + impl Borrow for [u8] { + #[inline] + fn borrow(&self) -> &BStr { + self.as_bstr() + } + } + + impl Borrow for str { + #[inline] + fn borrow(&self) -> &BStr { + self.as_bytes().as_bstr() + } + } + + impl Borrow<[u8]> for BStr { + #[inline] + fn borrow(&self) -> &[u8] { + self.as_bytes() + } + } + + impl BorrowMut for [u8] { + #[inline] + fn borrow_mut(&mut self) -> &mut BStr { + BStr::new_mut(self) + } + } + + impl BorrowMut<[u8]> for BStr { + #[inline] + fn borrow_mut(&mut self) -> &mut [u8] { + self.as_bytes_mut() + } + } + impl<'a> Default for &'a BStr { fn default() -> &'a BStr { BStr::from_bytes(b"") -- cgit v1.2.3