Skip to content

Commit 20dcefa

Browse files
committed
cosmwasm-std: avoid dependency on std::error::Error
std::error::Error doesn’t currently have a stable no_std equivalence. core::error::Error is a thing but it’s unstable and thus requires nightly compiler. There’s one hack we can use. serde has no_std support and exports std::error::Error as serde::de::StdErr. This way we hide the need for nightly compiler to serde. The two alternatives are: - require nightly compiler or - don’t implement std::error::Error in no_std builds. Issue: #1484
1 parent 2a0cfd9 commit 20dcefa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/std/src/errors/system_error.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ pub enum SystemError {
3939
},
4040
}
4141

42-
impl std::error::Error for SystemError {}
42+
// We want to support no_std thus we don’t want to reference Error through
43+
// std::error module. At the same time we don’t want to use core::error since
44+
// that’s unstable. Fortunately, we can take advantage of serde which
45+
// re-exports the trait as serde::de::StdError.
46+
impl serde::de::StdErr for SystemError {}
4347

4448
impl core::fmt::Display for SystemError {
4549
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

0 commit comments

Comments
 (0)