shared_vec/impls/
error.rs

1//! See the implementation for [`alloc::string::String`] as [`core::error::Error`] for more details.
2use crate::{Counter, String};
3use alloc::boxed::Box;
4use core::error::Error;
5use core::fmt;
6
7struct StringError<C: Counter<usize>>(String<C>);
8
9impl<C: Counter<usize>> Error for StringError<C> {}
10
11impl<C: Counter<usize>> fmt::Display for StringError<C> {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        fmt::Display::fmt(&self.0, f)
14    }
15}
16
17// Purposefully skip printing "StringError(..)"
18impl<C: Counter<usize>> fmt::Debug for StringError<C> {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        fmt::Debug::fmt(&self.0, f)
21    }
22}
23
24impl<'a, C: Counter<usize> + Send + Sync + 'a> From<String<C>>
25    for Box<dyn Error + Send + Sync + 'a>
26{
27    #[inline]
28    fn from(err: String<C>) -> Self {
29        Box::new(StringError(err))
30    }
31}
32impl<'a, C: Counter<usize> + Send + Sync + 'a> From<String<C>> for Box<dyn Error + Send + 'a> {
33    #[inline]
34    fn from(err: String<C>) -> Self {
35        Box::new(StringError(err))
36    }
37}
38impl<'a, C: Counter<usize> + 'a> From<String<C>> for Box<dyn Error + 'a> {
39    #[inline]
40    fn from(err: String<C>) -> Self {
41        Box::new(StringError(err))
42    }
43}