/rust/registry/src/index.crates.io-1949cf8c6b5b557f/bstr-1.12.0/src/bstring.rs
Line | Count | Source |
1 | | use alloc::vec::Vec; |
2 | | |
3 | | use crate::bstr::BStr; |
4 | | |
5 | | /// A wrapper for `Vec<u8>` that provides convenient string oriented trait |
6 | | /// impls. |
7 | | /// |
8 | | /// A `BString` has ownership over its contents and corresponds to |
9 | | /// a growable or shrinkable buffer. Its borrowed counterpart is a |
10 | | /// [`BStr`](struct.BStr.html), called a byte string slice. |
11 | | /// |
12 | | /// Using a `BString` is just like using a `Vec<u8>`, since `BString` |
13 | | /// implements `Deref` to `Vec<u8>`. So all methods available on `Vec<u8>` |
14 | | /// are also available on `BString`. |
15 | | /// |
16 | | /// # Examples |
17 | | /// |
18 | | /// You can create a new `BString` from a `Vec<u8>` via a `From` impl: |
19 | | /// |
20 | | /// ``` |
21 | | /// use bstr::BString; |
22 | | /// |
23 | | /// let s = BString::from("Hello, world!"); |
24 | | /// ``` |
25 | | /// |
26 | | /// # Deref |
27 | | /// |
28 | | /// The `BString` type implements `Deref` and `DerefMut`, where the target |
29 | | /// types are `&Vec<u8>` and `&mut Vec<u8>`, respectively. `Deref` permits all of the |
30 | | /// methods defined on `Vec<u8>` to be implicitly callable on any `BString`. |
31 | | /// |
32 | | /// For more information about how deref works, see the documentation for the |
33 | | /// [`std::ops::Deref`](https://doc.rust-lang.org/std/ops/trait.Deref.html) |
34 | | /// trait. |
35 | | /// |
36 | | /// # Representation |
37 | | /// |
38 | | /// A `BString` has the same representation as a `Vec<u8>` and a `String`. |
39 | | /// That is, it is made up of three word sized components: a pointer to a |
40 | | /// region of memory containing the bytes, a length and a capacity. |
41 | | #[derive(Clone)] |
42 | | pub struct BString { |
43 | | bytes: Vec<u8>, |
44 | | } |
45 | | |
46 | | impl BString { |
47 | | /// Constructs a new `BString` from the given [`Vec`]. |
48 | | /// |
49 | | /// # Examples |
50 | | /// |
51 | | /// ``` |
52 | | /// use bstr::BString; |
53 | | /// |
54 | | /// let mut b = BString::new(Vec::with_capacity(10)); |
55 | | /// ``` |
56 | | /// |
57 | | /// This function is `const`: |
58 | | /// |
59 | | /// ``` |
60 | | /// use bstr::BString; |
61 | | /// |
62 | | /// const B: BString = BString::new(vec![]); |
63 | | /// ``` |
64 | | #[inline] |
65 | 15.8M | pub const fn new(bytes: Vec<u8>) -> BString { |
66 | 15.8M | BString { bytes } |
67 | 15.8M | } <bstr::bstring::BString>::new Line | Count | Source | 65 | 5.73M | pub const fn new(bytes: Vec<u8>) -> BString { | 66 | 5.73M | BString { bytes } | 67 | 5.73M | } |
<bstr::bstring::BString>::new Line | Count | Source | 65 | 2.57M | pub const fn new(bytes: Vec<u8>) -> BString { | 66 | 2.57M | BString { bytes } | 67 | 2.57M | } |
<bstr::bstring::BString>::new Line | Count | Source | 65 | 7.47M | pub const fn new(bytes: Vec<u8>) -> BString { | 66 | 7.47M | BString { bytes } | 67 | 7.47M | } |
<bstr::bstring::BString>::new Line | Count | Source | 65 | 20.0k | pub const fn new(bytes: Vec<u8>) -> BString { | 66 | 20.0k | BString { bytes } | 67 | 20.0k | } |
|
68 | | |
69 | | #[inline] |
70 | 324k | pub(crate) fn as_bytes(&self) -> &[u8] { |
71 | 324k | &self.bytes |
72 | 324k | } Unexecuted instantiation: <bstr::bstring::BString>::as_bytes <bstr::bstring::BString>::as_bytes Line | Count | Source | 70 | 315k | pub(crate) fn as_bytes(&self) -> &[u8] { | 71 | 315k | &self.bytes | 72 | 315k | } |
<bstr::bstring::BString>::as_bytes Line | Count | Source | 70 | 2.63k | pub(crate) fn as_bytes(&self) -> &[u8] { | 71 | 2.63k | &self.bytes | 72 | 2.63k | } |
<bstr::bstring::BString>::as_bytes Line | Count | Source | 70 | 6.00k | pub(crate) fn as_bytes(&self) -> &[u8] { | 71 | 6.00k | &self.bytes | 72 | 6.00k | } |
|
73 | | |
74 | | #[inline] |
75 | 0 | pub(crate) fn as_bytes_mut(&mut self) -> &mut [u8] { |
76 | 0 | &mut self.bytes |
77 | 0 | } Unexecuted instantiation: <bstr::bstring::BString>::as_bytes_mut Unexecuted instantiation: <bstr::bstring::BString>::as_bytes_mut Unexecuted instantiation: <bstr::bstring::BString>::as_bytes_mut Unexecuted instantiation: <bstr::bstring::BString>::as_bytes_mut |
78 | | |
79 | | #[inline] |
80 | 3.65M | pub(crate) fn as_bstr(&self) -> &BStr { |
81 | 3.65M | BStr::new(&self.bytes) |
82 | 3.65M | } <bstr::bstring::BString>::as_bstr Line | Count | Source | 80 | 3.59M | pub(crate) fn as_bstr(&self) -> &BStr { | 81 | 3.59M | BStr::new(&self.bytes) | 82 | 3.59M | } |
<bstr::bstring::BString>::as_bstr Line | Count | Source | 80 | 5.69k | pub(crate) fn as_bstr(&self) -> &BStr { | 81 | 5.69k | BStr::new(&self.bytes) | 82 | 5.69k | } |
<bstr::bstring::BString>::as_bstr Line | Count | Source | 80 | 38.2k | pub(crate) fn as_bstr(&self) -> &BStr { | 81 | 38.2k | BStr::new(&self.bytes) | 82 | 38.2k | } |
<bstr::bstring::BString>::as_bstr Line | Count | Source | 80 | 7.12k | pub(crate) fn as_bstr(&self) -> &BStr { | 81 | 7.12k | BStr::new(&self.bytes) | 82 | 7.12k | } |
|
83 | | |
84 | | #[inline] |
85 | 0 | pub(crate) fn as_mut_bstr(&mut self) -> &mut BStr { |
86 | 0 | BStr::new_mut(&mut self.bytes) |
87 | 0 | } Unexecuted instantiation: <bstr::bstring::BString>::as_mut_bstr Unexecuted instantiation: <bstr::bstring::BString>::as_mut_bstr Unexecuted instantiation: <bstr::bstring::BString>::as_mut_bstr Unexecuted instantiation: <bstr::bstring::BString>::as_mut_bstr |
88 | | |
89 | | #[inline] |
90 | 376k | pub(crate) fn as_vec(&self) -> &Vec<u8> { |
91 | 376k | &self.bytes |
92 | 376k | } <bstr::bstring::BString>::as_vec Line | Count | Source | 90 | 10.5k | pub(crate) fn as_vec(&self) -> &Vec<u8> { | 91 | 10.5k | &self.bytes | 92 | 10.5k | } |
<bstr::bstring::BString>::as_vec Line | Count | Source | 90 | 12.4k | pub(crate) fn as_vec(&self) -> &Vec<u8> { | 91 | 12.4k | &self.bytes | 92 | 12.4k | } |
<bstr::bstring::BString>::as_vec Line | Count | Source | 90 | 335k | pub(crate) fn as_vec(&self) -> &Vec<u8> { | 91 | 335k | &self.bytes | 92 | 335k | } |
<bstr::bstring::BString>::as_vec Line | Count | Source | 90 | 18.0k | pub(crate) fn as_vec(&self) -> &Vec<u8> { | 91 | 18.0k | &self.bytes | 92 | 18.0k | } |
|
93 | | |
94 | | #[inline] |
95 | 233M | pub(crate) fn as_vec_mut(&mut self) -> &mut Vec<u8> { |
96 | 233M | &mut self.bytes |
97 | 233M | } <bstr::bstring::BString>::as_vec_mut Line | Count | Source | 95 | 186M | pub(crate) fn as_vec_mut(&mut self) -> &mut Vec<u8> { | 96 | 186M | &mut self.bytes | 97 | 186M | } |
<bstr::bstring::BString>::as_vec_mut Line | Count | Source | 95 | 17.4M | pub(crate) fn as_vec_mut(&mut self) -> &mut Vec<u8> { | 96 | 17.4M | &mut self.bytes | 97 | 17.4M | } |
<bstr::bstring::BString>::as_vec_mut Line | Count | Source | 95 | 29.4M | pub(crate) fn as_vec_mut(&mut self) -> &mut Vec<u8> { | 96 | 29.4M | &mut self.bytes | 97 | 29.4M | } |
Unexecuted instantiation: <bstr::bstring::BString>::as_vec_mut |
98 | | |
99 | | #[inline] |
100 | 0 | pub(crate) fn into_vec(self) -> Vec<u8> { |
101 | 0 | self.bytes |
102 | 0 | } Unexecuted instantiation: <bstr::bstring::BString>::into_vec Unexecuted instantiation: <bstr::bstring::BString>::into_vec Unexecuted instantiation: <bstr::bstring::BString>::into_vec Unexecuted instantiation: <bstr::bstring::BString>::into_vec |
103 | | } |