File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,43 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
194
194
}
195
195
}
196
196
197
+ #[ unstable( feature = "box_error_send" , issue = "none" ) ]
198
+ impl < ' a , E : Error + Send + ' a > From < E > for Box < dyn Error + Send + ' a > {
199
+ /// Converts a type of [`Error`] + [`Send`] into a box of dyn [`Error`] + [`Send`].
200
+ ///
201
+ /// [`Error`]: ../error/trait.Error.html
202
+ ///
203
+ /// # Examples
204
+ ///
205
+ /// ```
206
+ /// use std::error::Error;
207
+ /// use std::fmt;
208
+ /// use std::mem;
209
+ ///
210
+ /// #[derive(Debug)]
211
+ /// struct AnError;
212
+ ///
213
+ /// impl fmt::Display for AnError {
214
+ /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
215
+ /// write!(f , "An error")
216
+ /// }
217
+ /// }
218
+ ///
219
+ /// impl Error for AnError {}
220
+ ///
221
+ /// unsafe impl Send for AnError {}
222
+ ///
223
+ /// let an_error = AnError;
224
+ /// assert!(0 == mem::size_of_val(&an_error));
225
+ /// let a_boxed_error = Box::<dyn Error + Send>::from(an_error);
226
+ /// assert!(
227
+ /// mem::size_of::<Box<dyn Error + Send>>() == mem::size_of_val(&a_boxed_error))
228
+ /// ```
229
+ fn from ( err : E ) -> Box < dyn Error + Send + ' a > {
230
+ Box :: new ( err)
231
+ }
232
+ }
233
+
197
234
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
198
235
impl < ' a , E : Error + Send + Sync + ' a > From < E > for Box < dyn Error + Send + Sync + ' a > {
199
236
/// Converts a type of [`Error`] + [`Send`] + [`Sync`] into a box of
You can’t perform that action at this time.
0 commit comments