diff options
-rwxr-xr-x | pre-commit.sh | 3 | ||||
-rw-r--r-- | src/lib.rs | 15 |
2 files changed, 13 insertions, 5 deletions
diff --git a/pre-commit.sh b/pre-commit.sh index bcffdca..603bc0f 100755 --- a/pre-commit.sh +++ b/pre-commit.sh @@ -1,4 +1,7 @@ #!/bin/sh cargo fmt || exit 1 +cargo check || exit 1 cargo clippy -- -D warnings || exit 1 +# Check that there are no errors with no_std +cargo check --target=wasm32-unknown-unknown --no-default-features || exit 1 git add -u || exit 1 @@ -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()); |