| { | ||
| "git": { | ||
| "sha1": "cabbfe32c3c321671b8b983a39a860df5a2be4a1" | ||
| "sha1": "63c6578f22bb8eda35a983e5c937d79c16b2a355" | ||
| }, | ||
| "path_in_vcs": "" | ||
| } |
+1
-1
@@ -7,3 +7,3 @@ # This file is automatically @generated by Cargo. | ||
| name = "bstr" | ||
| version = "1.12.3" | ||
| version = "1.13.0" | ||
| dependencies = [ | ||
@@ -10,0 +10,0 @@ "memchr", |
+1
-1
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "bstr" | ||
| version = "1.12.3" | ||
| version = "1.13.0" | ||
| authors = ["Andrew Gallant <jamslam@gmail.com>"] | ||
@@ -19,0 +19,0 @@ build = false |
+19
-0
@@ -42,2 +42,3 @@ use alloc::vec::Vec; | ||
| #[derive(Clone)] | ||
| #[repr(transparent)] | ||
| pub struct BString { | ||
@@ -104,2 +105,20 @@ bytes: Vec<u8>, | ||
| } | ||
| #[inline] | ||
| pub(crate) fn from_vec_ref(v: &Vec<u8>) -> &BString { | ||
| // SAFETY: `BString` is a `repr(transparent)` wrapper around `Vec<u8>`, and accepts any | ||
| // `Vec<u8>` without validation. | ||
| // | ||
| // MSRV: Switch this to use `ptr::from_ref` once bstr can require at least Rust 1.72. | ||
| unsafe { &*(v as *const Vec<u8> as *const BString) } | ||
| } | ||
| #[inline] | ||
| pub(crate) fn from_vec_mut(v: &mut Vec<u8>) -> &mut BString { | ||
| // SAFETY: `BString` is a `repr(transparent)` wrapper around `Vec<u8>`, and accepts any | ||
| // `Vec<u8>` without validation. | ||
| // | ||
| // MSRV: Switch this to use `ptr::from_mut` once bstr can require at least Rust 1.72. | ||
| unsafe { &mut *(v as *mut Vec<u8> as *mut BString) } | ||
| } | ||
| } |
+83
-0
@@ -15,2 +15,3 @@ use core::{fmt, iter, ops, ptr}; | ||
| utf8::{self, Utf8Error}, | ||
| BString, | ||
| }; | ||
@@ -145,2 +146,84 @@ | ||
| /// Convert this type to a `BString`. | ||
| /// | ||
| /// `BString` is useful if you want its trait implementations such as `Debug`, `PartialEq`, and | ||
| /// `PartialOrd`, or if you want to declare at an interface boundary (field or parameter) that | ||
| /// something uses "conventionally UTF-8" owned strings. | ||
| /// | ||
| /// This is a zero-cost conversion. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// Basic usage: | ||
| /// | ||
| /// ``` | ||
| /// use bstr::ByteVec; | ||
| /// | ||
| /// let v = vec![b'a', b'b', b'c']; | ||
| /// let b = v.to_bstring(); | ||
| /// println!("{b}"); | ||
| /// assert_eq!(b, "abc"); | ||
| /// assert_ne!(b, "hello"); | ||
| /// ``` | ||
| #[inline] | ||
| fn to_bstring(self) -> BString | ||
| where | ||
| Self: Sized, | ||
| { | ||
| BString::new(self.into_vec()) | ||
| } | ||
| /// Convert a `&Vec<u8>` to a `&BString`, without copying. | ||
| /// | ||
| /// `BString` is useful if you want its trait implementations such as `Debug`, `PartialEq`, and | ||
| /// `PartialOrd`, or if you want to declare at an interface boundary (field or parameter) that | ||
| /// something uses "conventionally UTF-8" owned strings. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// Basic usage: | ||
| /// | ||
| /// ``` | ||
| /// use bstr::ByteVec; | ||
| /// | ||
| /// let mut v = vec![b'a', b'b', b'c']; | ||
| /// let b = v.as_bstring(); | ||
| /// println!("{b}"); | ||
| /// assert_eq!(b, "abc"); | ||
| /// assert_ne!(b, "hello"); | ||
| /// // no references to `b` after this point | ||
| /// v.push(b'd'); | ||
| /// assert_eq!(v, [b'a', b'b', b'c', b'd']); | ||
| /// ``` | ||
| #[inline] | ||
| fn as_bstring(&self) -> &BString { | ||
| BString::from_vec_ref(self.as_vec()) | ||
| } | ||
| /// Convert a `&mut Vec<u8>` to a `&mut BString`, without copying. | ||
| /// | ||
| /// `BString` is useful if you want its trait implementations such as `Debug`, `PartialEq`, and | ||
| /// `PartialOrd`, or if you want to declare at an interface boundary (field or parameter) that | ||
| /// something uses "conventionally UTF-8" owned strings. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// Basic usage: | ||
| /// | ||
| /// ``` | ||
| /// use bstr::ByteVec; | ||
| /// | ||
| /// let mut v = vec![b'a', b'b', b'c']; | ||
| /// let b = v.as_bstring_mut(); | ||
| /// println!("{b}"); | ||
| /// assert_eq!(b, "abc"); | ||
| /// assert_ne!(b, "hello"); | ||
| /// b.push_str("de"); | ||
| /// assert_eq!(v, [b'a', b'b', b'c', b'd', b'e']); | ||
| /// ``` | ||
| #[inline] | ||
| fn as_bstring_mut(&mut self) -> &mut BString { | ||
| BString::from_vec_mut(self.as_vec_mut()) | ||
| } | ||
| /// Create a new owned byte string from the given byte slice. | ||
@@ -147,0 +230,0 @@ /// |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display