@@ -109,6 +109,29 @@ impl<T: Clone> From<&[T]> for Box<[T]> {
109109 }
110110}
111111
112+ #[ cfg( not( no_global_oom_handling) ) ]
113+ #[ stable( feature = "box_from_mut_slice" , since = "CURRENT_RUSTC_VERSION" ) ]
114+ impl < T : Clone > From < & mut [ T ] > for Box < [ T ] > {
115+ /// Converts a `&mut [T]` into a `Box<[T]>`
116+ ///
117+ /// This conversion allocates on the heap
118+ /// and performs a copy of `slice` and its contents.
119+ ///
120+ /// # Examples
121+ /// ```rust
122+ /// // create a &mut [u8] which will be used to create a Box<[u8]>
123+ /// let mut array = [104, 101, 108, 108, 111];
124+ /// let slice: &mut [u8] = &mut array;
125+ /// let boxed_slice: Box<[u8]> = Box::from(slice);
126+ ///
127+ /// println!("{boxed_slice:?}");
128+ /// ```
129+ #[ inline]
130+ fn from ( slice : & mut [ T ] ) -> Box < [ T ] > {
131+ Self :: from ( & * slice)
132+ }
133+ }
134+
112135#[ cfg( not( no_global_oom_handling) ) ]
113136#[ stable( feature = "box_from_cow" , since = "1.45.0" ) ]
114137impl < T : Clone > From < Cow < ' _ , [ T ] > > for Box < [ T ] > {
@@ -147,6 +170,28 @@ impl From<&str> for Box<str> {
147170 }
148171}
149172
173+ #[ cfg( not( no_global_oom_handling) ) ]
174+ #[ stable( feature = "box_from_mut_slice" , since = "CURRENT_RUSTC_VERSION" ) ]
175+ impl From < & mut str > for Box < str > {
176+ /// Converts a `&mut str` into a `Box<str>`
177+ ///
178+ /// This conversion allocates on the heap
179+ /// and performs a copy of `s`.
180+ ///
181+ /// # Examples
182+ ///
183+ /// ```rust
184+ /// let mut original = String::from("hello");
185+ /// let original: &mut str = &mut original;
186+ /// let boxed: Box<str> = Box::from(original);
187+ /// println!("{boxed}");
188+ /// ```
189+ #[ inline]
190+ fn from ( s : & mut str ) -> Box < str > {
191+ Self :: from ( & * s)
192+ }
193+ }
194+
150195#[ cfg( not( no_global_oom_handling) ) ]
151196#[ stable( feature = "box_from_cow" , since = "1.45.0" ) ]
152197impl From < Cow < ' _ , str > > for Box < str > {
0 commit comments