From 9841143d0c5ce040b303b484c474528034919a16 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Thu, 8 Aug 2024 10:20:56 -0500 Subject: [PATCH] Make noun::Error an instance of std::error::Error --- rust/ares/src/noun.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rust/ares/src/noun.rs b/rust/ares/src/noun.rs index 3ce5f80..1e2489f 100644 --- a/rust/ares/src/noun.rs +++ b/rust/ares/src/noun.rs @@ -4,6 +4,7 @@ use bitvec::prelude::{BitSlice, Lsb0}; use either::{Either, Left, Right}; use ibig::{Stack, UBig}; use intmap::IntMap; +use std::error; use std::fmt; use std::ptr; use std::slice::{from_raw_parts, from_raw_parts_mut}; @@ -172,6 +173,21 @@ pub enum Error { NotRepresentable, } +impl error::Error for Error {} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result { + match self { + Error::NotAllocated => f.write_str("not an allocated noun"), + Error::NotAtom => f.write_str("not an atom"), + Error::NotCell => f.write_str("not a cell"), + Error::NotDirectAtom => f.write_str("not a direct atom"), + Error::NotIndirectAtom => f.write_str("not an indirect atom"), + Error::NotRepresentable => f.write_str("unrepresentable value"), + } + } +} + impl From for () { fn from(_: Error) -> Self {} }