diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-02-16 19:23:37 +0800 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-04-14 21:53:11 +0300 |
| commit | 5bee741a08a267f68ac6c3d24dadfe927bd45008 (patch) | |
| tree | 405bb0b23d2fea185c8ef2cfea2a387284c1ba7d /library/std/src/error.rs | |
| parent | e7575f9670f3c837def3d186ae09366c75c7632e (diff) | |
| download | rust-5bee741a08a267f68ac6c3d24dadfe927bd45008.tar.gz rust-5bee741a08a267f68ac6c3d24dadfe927bd45008.zip | |
library: Move `CStr` to libcore, and `CString` to liballoc
Diffstat (limited to 'library/std/src/error.rs')
| -rw-r--r-- | library/std/src/error.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/library/std/src/error.rs b/library/std/src/error.rs index 4fb94908c80..3f85c2095cb 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -26,6 +26,7 @@ use crate::borrow::Cow; use crate::cell; use crate::char; use crate::fmt::{self, Debug, Display, Write}; +use crate::io; use crate::mem::transmute; use crate::num; use crate::str; @@ -612,6 +613,48 @@ impl Error for alloc::collections::TryReserveError {} #[unstable(feature = "duration_checked_float", issue = "83400")] impl Error for time::FromFloatSecsError {} +#[stable(feature = "rust1", since = "1.0.0")] +impl Error for alloc::ffi::NulError { + #[allow(deprecated)] + fn description(&self) -> &str { + "nul byte found in data" + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl From<alloc::ffi::NulError> for io::Error { + /// Converts a [`alloc::ffi::NulError`] into a [`io::Error`]. + fn from(_: alloc::ffi::NulError) -> io::Error { + io::const_io_error!(io::ErrorKind::InvalidInput, "data provided contains a nul byte") + } +} + +#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] +impl Error for core::ffi::FromBytesWithNulError { + #[allow(deprecated)] + fn description(&self) -> &str { + self.__description() + } +} + +#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] +impl Error for core::ffi::FromBytesUntilNulError {} + +#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")] +impl Error for alloc::ffi::FromVecWithNulError {} + +#[stable(feature = "cstring_into", since = "1.7.0")] +impl Error for alloc::ffi::IntoStringError { + #[allow(deprecated)] + fn description(&self) -> &str { + "C string contained non-utf8 bytes" + } + + fn source(&self) -> Option<&(dyn Error + 'static)> { + Some(self.__source()) + } +} + // Copied from `any.rs`. impl dyn Error + 'static { /// Returns `true` if the inner type is the same as `T`. |
