@@ -63,14 +63,16 @@ impl ByteStr {
63
63
/// ```
64
64
#[ inline]
65
65
#[ unstable( feature = "bstr" , issue = "134915" ) ]
66
- pub fn new < B : ?Sized + AsRef < [ u8 ] > > ( bytes : & B ) -> & Self {
66
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
67
+ pub const fn new < B : ?Sized + [ const ] AsRef < [ u8 ] > > ( bytes : & B ) -> & Self {
67
68
ByteStr :: from_bytes ( bytes. as_ref ( ) )
68
69
}
69
70
70
71
#[ doc( hidden) ]
71
72
#[ unstable( feature = "bstr_internals" , issue = "none" ) ]
72
73
#[ inline]
73
- pub fn from_bytes ( slice : & [ u8 ] ) -> & Self {
74
+ #[ rustc_const_unstable( feature = "bstr_internals" , issue = "none" ) ]
75
+ pub const fn from_bytes ( slice : & [ u8 ] ) -> & Self {
74
76
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`, so we can turn a reference to
75
77
// the wrapped type into a reference to the wrapper type.
76
78
unsafe { & * ( slice as * const [ u8 ] as * const Self ) }
@@ -79,7 +81,8 @@ impl ByteStr {
79
81
#[ doc( hidden) ]
80
82
#[ unstable( feature = "bstr_internals" , issue = "none" ) ]
81
83
#[ inline]
82
- pub fn from_bytes_mut ( slice : & mut [ u8 ] ) -> & mut Self {
84
+ #[ rustc_const_unstable( feature = "bstr_internals" , issue = "none" ) ]
85
+ pub const fn from_bytes_mut ( slice : & mut [ u8 ] ) -> & mut Self {
83
86
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`, so we can turn a reference to
84
87
// the wrapped type into a reference to the wrapper type.
85
88
unsafe { & mut * ( slice as * mut [ u8 ] as * mut Self ) }
@@ -88,20 +91,23 @@ impl ByteStr {
88
91
#[ doc( hidden) ]
89
92
#[ unstable( feature = "bstr_internals" , issue = "none" ) ]
90
93
#[ inline]
91
- pub fn as_bytes ( & self ) -> & [ u8 ] {
94
+ #[ rustc_const_unstable( feature = "bstr_internals" , issue = "none" ) ]
95
+ pub const fn as_bytes ( & self ) -> & [ u8 ] {
92
96
& self . 0
93
97
}
94
98
95
99
#[ doc( hidden) ]
96
100
#[ unstable( feature = "bstr_internals" , issue = "none" ) ]
97
101
#[ inline]
98
- pub fn as_bytes_mut ( & mut self ) -> & mut [ u8 ] {
102
+ #[ rustc_const_unstable( feature = "bstr_internals" , issue = "none" ) ]
103
+ pub const fn as_bytes_mut ( & mut self ) -> & mut [ u8 ] {
99
104
& mut self . 0
100
105
}
101
106
}
102
107
103
108
#[ unstable( feature = "bstr" , issue = "134915" ) ]
104
- impl Deref for ByteStr {
109
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
110
+ impl const Deref for ByteStr {
105
111
type Target = [ u8 ] ;
106
112
107
113
#[ inline]
@@ -111,7 +117,8 @@ impl Deref for ByteStr {
111
117
}
112
118
113
119
#[ unstable( feature = "bstr" , issue = "134915" ) ]
114
- impl DerefMut for ByteStr {
120
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
121
+ impl const DerefMut for ByteStr {
115
122
#[ inline]
116
123
fn deref_mut ( & mut self ) -> & mut [ u8 ] {
117
124
& mut self . 0
@@ -185,15 +192,17 @@ impl fmt::Display for ByteStr {
185
192
}
186
193
187
194
#[ unstable( feature = "bstr" , issue = "134915" ) ]
188
- impl AsRef < [ u8 ] > for ByteStr {
195
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
196
+ impl const AsRef < [ u8 ] > for ByteStr {
189
197
#[ inline]
190
198
fn as_ref ( & self ) -> & [ u8 ] {
191
199
& self . 0
192
200
}
193
201
}
194
202
195
203
#[ unstable( feature = "bstr" , issue = "134915" ) ]
196
- impl AsRef < ByteStr > for ByteStr {
204
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
205
+ impl const AsRef < ByteStr > for ByteStr {
197
206
#[ inline]
198
207
fn as_ref ( & self ) -> & ByteStr {
199
208
self
@@ -203,15 +212,17 @@ impl AsRef<ByteStr> for ByteStr {
203
212
// `impl AsRef<ByteStr> for [u8]` omitted to avoid widespread inference failures
204
213
205
214
#[ unstable( feature = "bstr" , issue = "134915" ) ]
206
- impl AsRef < ByteStr > for str {
215
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
216
+ impl const AsRef < ByteStr > for str {
207
217
#[ inline]
208
218
fn as_ref ( & self ) -> & ByteStr {
209
219
ByteStr :: new ( self )
210
220
}
211
221
}
212
222
213
223
#[ unstable( feature = "bstr" , issue = "134915" ) ]
214
- impl AsMut < [ u8 ] > for ByteStr {
224
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
225
+ impl const AsMut < [ u8 ] > for ByteStr {
215
226
#[ inline]
216
227
fn as_mut ( & mut self ) -> & mut [ u8 ] {
217
228
& mut self . 0
@@ -225,7 +236,8 @@ impl AsMut<[u8]> for ByteStr {
225
236
// `impl Borrow<ByteStr> for str` omitted to avoid widespread inference failures
226
237
227
238
#[ unstable( feature = "bstr" , issue = "134915" ) ]
228
- impl Borrow < [ u8 ] > for ByteStr {
239
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
240
+ impl const Borrow < [ u8 ] > for ByteStr {
229
241
#[ inline]
230
242
fn borrow ( & self ) -> & [ u8 ] {
231
243
& self . 0
@@ -235,7 +247,8 @@ impl Borrow<[u8]> for ByteStr {
235
247
// `impl BorrowMut<ByteStr> for [u8]` omitted to avoid widespread inference failures
236
248
237
249
#[ unstable( feature = "bstr" , issue = "134915" ) ]
238
- impl BorrowMut < [ u8 ] > for ByteStr {
250
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
251
+ impl const BorrowMut < [ u8 ] > for ByteStr {
239
252
#[ inline]
240
253
fn borrow_mut ( & mut self ) -> & mut [ u8 ] {
241
254
& mut self . 0
@@ -303,7 +316,8 @@ impl<'a> Default for &'a mut ByteStr {
303
316
// }
304
317
305
318
#[ unstable( feature = "bstr" , issue = "134915" ) ]
306
- impl < ' a > TryFrom < & ' a ByteStr > for & ' a str {
319
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
320
+ impl < ' a > const TryFrom < & ' a ByteStr > for & ' a str {
307
321
type Error = crate :: str:: Utf8Error ;
308
322
309
323
#[ inline]
@@ -313,7 +327,8 @@ impl<'a> TryFrom<&'a ByteStr> for &'a str {
313
327
}
314
328
315
329
#[ unstable( feature = "bstr" , issue = "134915" ) ]
316
- impl < ' a > TryFrom < & ' a mut ByteStr > for & ' a mut str {
330
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "143773" ) ]
331
+ impl < ' a > const TryFrom < & ' a mut ByteStr > for & ' a mut str {
317
332
type Error = crate :: str:: Utf8Error ;
318
333
319
334
#[ inline]
0 commit comments