diff --git a/src/btreemap.rs b/src/btreemap.rs index ec4a8e72..9c45ec13 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -36,9 +36,9 @@ use allocator::Allocator; pub use iter::Iter; use iter::{Cursor, Index}; use node::{DerivedPageSize, Entry, Node, NodeType, PageSize, Version}; -use std::borrow::Cow; use std::marker::PhantomData; use std::ops::{Bound, RangeBounds}; +use std::{borrow::Cow, fmt}; #[cfg(test)] mod proptests; @@ -1194,8 +1194,8 @@ pub enum InsertError { ValueTooLarge { given: usize, max: usize }, } -impl std::fmt::Display for InsertError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for InsertError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::KeyTooLarge { given, max } => { write!( diff --git a/src/cell.rs b/src/cell.rs index f569b6eb..47b09a37 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -2,6 +2,7 @@ use crate::storable::Storable; use crate::{Memory, WASM_PAGE_SIZE}; use std::borrow::{Borrow, Cow}; +use std::fmt; #[cfg(test)] mod tests; @@ -45,6 +46,26 @@ pub enum InitError { ValueTooLarge { value_size: u64 }, } +impl fmt::Display for InitError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + InitError::IncompatibleVersion { + last_supported_version, + decoded_version, + } => write!( + f, + "Incompatible version: last supported version is {}, but the memory contains version {}", + last_supported_version, decoded_version + ), + InitError::ValueTooLarge { value_size } => write!( + f, + "The initial value is too large to fit into the memory: {} bytes", + value_size + ), + } + } +} + /// Indicates a failure to set cell's value. #[derive(Debug, PartialEq, Eq)] pub enum ValueError { diff --git a/src/log.rs b/src/log.rs index 03b8f1b3..9a273f0a 100644 --- a/src/log.rs +++ b/src/log.rs @@ -57,6 +57,7 @@ use crate::{read_u64, safe_write, write_u64, Address, GrowFailed, Memory, Storable}; use std::borrow::Cow; use std::cell::RefCell; +use std::fmt; use std::marker::PhantomData; use std::thread::LocalKey; @@ -98,6 +99,30 @@ pub enum InitError { InvalidIndex, } +impl fmt::Display for InitError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + InitError::IncompatibleDataVersion { + last_supported_version, + decoded_version, + } => write!( + f, + "Incompatible data version: last supported version is {}, but decoded version is {}", + last_supported_version, decoded_version + ), + InitError::IncompatibleIndexVersion { + last_supported_version, + decoded_version, + } => write!( + f, + "Incompatible index version: last supported version is {}, but decoded version is {}", + last_supported_version, decoded_version + ), + InitError::InvalidIndex => write!(f, "Invalid index"), + } + } +} + #[derive(Debug, PartialEq, Eq)] pub enum WriteError { GrowFailed { current_size: u64, delta: u64 },