diff options
author | pommicket <pommicket@gmail.com> | 2025-09-08 12:03:54 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-08 12:03:54 -0400 |
commit | eb93ed0b575a612af02e14b660e30486c27b9863 (patch) | |
tree | 22fd2ea14af20c23037b1bc053226eed13c7c7e7 /src | |
parent | 20417bbb3fe8a75d648d20c0d2cf6c112bfdf114 (diff) |
Fix no_std build
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -5,8 +5,12 @@ #![warn(clippy::redundant_closure_for_method_calls)] extern crate alloc; +use alloc::borrow::ToOwned; +use alloc::boxed::Box; +use alloc::string::String; use alloc::sync::Arc; use alloc::vec::Vec; +use alloc::{format, vec}; use core::fmt; use core::mem::take; @@ -117,6 +121,7 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { + #[cfg(feature = "std")] Self::IO(message, io_err) => write!(f, "{message}: {io_err}"), Self::IllegalCharacter(location, c) => { write!(f, "{location}: illegal character {c:?}") @@ -174,17 +179,17 @@ impl fmt::Display for Error { } impl core::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { + #[cfg(feature = "std")] if let Error::IO(_, e) = self { - Some(e) - } else { - None + return Some(e); } + None } } /// Type alias for [`std::result::Result`] with [`Error`] as the error. -pub type Result<T> = std::result::Result<T, Error>; +pub type Result<T> = core::result::Result<T, Error>; fn parse_int(location: &Location, string: &str) -> Result<i64> { let bad_int = || Error::BadInt(location.clone(), string.into()); |