From fdde645a562345d447d9f43c3ee47db2766ea4d7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Mon, 15 Apr 2024 13:51:01 +0200 Subject: [PATCH 1/2] refactor: set up the storage and encoding crates --- crates/storey-encoding/Cargo.toml | 13 +++ crates/storey-encoding/src/lib.rs | 59 ++++++++++ crates/storey-storage/Cargo.toml | 13 +++ .../storage => storey-storage/src}/backend.rs | 2 +- crates/storey-storage/src/lib.rs | 5 + crates/storey-storage/src/storage.rs | 100 +++++++++++++++++ crates/storey/Cargo.toml | 15 ++- crates/storey/src/containers/mod.rs | 1 + crates/storey/src/containers/test_mocks.rs | 1 + crates/storey/src/encoding.rs | 62 +--------- crates/storey/src/storage/mod.rs | 106 +----------------- 11 files changed, 211 insertions(+), 166 deletions(-) create mode 100644 crates/storey-encoding/Cargo.toml create mode 100644 crates/storey-encoding/src/lib.rs create mode 100644 crates/storey-storage/Cargo.toml rename crates/{storey/src/storage => storey-storage/src}/backend.rs (97%) create mode 100644 crates/storey-storage/src/lib.rs create mode 100644 crates/storey-storage/src/storage.rs create mode 100644 crates/storey/src/containers/test_mocks.rs diff --git a/crates/storey-encoding/Cargo.toml b/crates/storey-encoding/Cargo.toml new file mode 100644 index 0000000..08fe6bf --- /dev/null +++ b/crates/storey-encoding/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "storey-encoding" +description = "Interfaces for storey encodings" +version = "0.1.0" +edition = "2021" +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +categories.workspace = true +keywords.workspace = true + +[dependencies] diff --git a/crates/storey-encoding/src/lib.rs b/crates/storey-encoding/src/lib.rs new file mode 100644 index 0000000..915bee2 --- /dev/null +++ b/crates/storey-encoding/src/lib.rs @@ -0,0 +1,59 @@ +pub trait Encoding { + type EncodeError; + type DecodeError; +} + +pub trait EncodableWith: sealed::SealedE { + fn encode(&self) -> Result, E::EncodeError>; +} + +pub trait EncodableWithImpl { + fn encode_impl(self) -> Result, E::EncodeError>; +} + +impl EncodableWith for T +where + for<'a> Cover<&'a T>: EncodableWithImpl, +{ + fn encode(&self) -> Result, ::EncodeError> { + Cover(self).encode_impl() + } +} + +pub trait DecodableWith: Sized + sealed::SealedD { + fn decode(data: &[u8]) -> Result; +} + +pub trait DecodableWithImpl: Sized { + fn decode_impl(data: &[u8]) -> Result; +} + +impl DecodableWith for T +where + Cover: DecodableWithImpl, +{ + fn decode(data: &[u8]) -> Result::DecodeError> { + let wrapper = >::decode_impl(data)?; + Ok(wrapper.0) + } +} + +mod sealed { + // This module is private to the crate. It's used to seal the `EncodableWith` and + // `DecodableWith` traits, so that the only way they can be implemented outside + // this crate is through the blanket implementations provided by `EncodableWithImpl` + // and `DecodableWithImpl`. + // + // More information on sealed traits: + // https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed + + use super::*; + + pub trait SealedE {} + pub trait SealedD {} + + impl SealedE for T where for<'a> Cover<&'a T>: EncodableWithImpl {} + impl SealedD for T where Cover: DecodableWithImpl {} +} + +pub struct Cover(pub T); diff --git a/crates/storey-storage/Cargo.toml b/crates/storey-storage/Cargo.toml new file mode 100644 index 0000000..783ffbb --- /dev/null +++ b/crates/storey-storage/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "storey-storage" +description = "Interfaces for storey storage backends" +version = "0.1.0" +edition = "2021" +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +categories.workspace = true +keywords.workspace = true + +[dependencies] diff --git a/crates/storey/src/storage/backend.rs b/crates/storey-storage/src/backend.rs similarity index 97% rename from crates/storey/src/storage/backend.rs rename to crates/storey-storage/src/backend.rs index a810a21..f112eeb 100644 --- a/crates/storey/src/storage/backend.rs +++ b/crates/storey-storage/src/backend.rs @@ -1,4 +1,4 @@ -use super::{Storage, StorageMut}; +use super::storage::{Storage, StorageMut}; pub trait StorageBackend { fn get(&self, key: &[u8]) -> Option>; diff --git a/crates/storey-storage/src/lib.rs b/crates/storey-storage/src/lib.rs new file mode 100644 index 0000000..2ae3a50 --- /dev/null +++ b/crates/storey-storage/src/lib.rs @@ -0,0 +1,5 @@ +mod backend; +mod storage; + +pub use backend::{StorageBackend, StorageBackendMut}; +pub use storage::{IterableStorage, RevIterableStorage, Storage, StorageMut}; diff --git a/crates/storey-storage/src/storage.rs b/crates/storey-storage/src/storage.rs new file mode 100644 index 0000000..88ca72a --- /dev/null +++ b/crates/storey-storage/src/storage.rs @@ -0,0 +1,100 @@ +pub trait Storage { + fn get(&self, key: &[u8]) -> Option>; + + fn has(&self, key: &[u8]) -> bool { + self.get(key).is_some() + } + + fn get_meta(&self, _key: &[u8]) -> Option>; + fn has_meta(&self, key: &[u8]) -> bool { + self.get_meta(key).is_some() + } +} + +pub trait StorageMut { + fn set(&mut self, key: &[u8], value: &[u8]); + fn remove(&mut self, key: &[u8]); + + fn set_meta(&mut self, _key: &[u8], _value: &[u8]); + fn remove_meta(&mut self, _key: &[u8]); +} + +pub trait IterableStorage { + type KeysIterator<'a>: Iterator> + where + Self: 'a; + type ValuesIterator<'a>: Iterator> + where + Self: 'a; + type PairsIterator<'a>: Iterator, Vec)> + where + Self: 'a; + + fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a>; + fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a>; + fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a>; +} + +impl IterableStorage for &T { + type KeysIterator<'a> = T::KeysIterator<'a> where Self: 'a; + type ValuesIterator<'a> = T::ValuesIterator<'a> where Self: 'a; + type PairsIterator<'a> = T::PairsIterator<'a> where Self: 'a; + + fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a> { + (**self).keys(start, end) + } + + fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a> { + (**self).values(start, end) + } + + fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a> { + (**self).pairs(start, end) + } +} + +impl IterableStorage for &mut T { + type KeysIterator<'a> = T::KeysIterator<'a> where Self: 'a; + type ValuesIterator<'a> = T::ValuesIterator<'a> where Self: 'a; + type PairsIterator<'a> = T::PairsIterator<'a> where Self: 'a; + + fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a> { + (**self).keys(start, end) + } + + fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a> { + (**self).values(start, end) + } + + fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a> { + (**self).pairs(start, end) + } +} + +pub trait RevIterableStorage { + type RevKeysIterator<'a>: Iterator> + where + Self: 'a; + type RevValuesIterator<'a>: Iterator> + where + Self: 'a; + type RevPairsIterator<'a>: Iterator, Vec)> + where + Self: 'a; + + fn rev_keys<'a>( + &'a self, + start: Option<&[u8]>, + end: Option<&[u8]>, + ) -> Self::RevKeysIterator<'a>; + fn rev_values<'a>( + &'a self, + start: Option<&[u8]>, + end: Option<&[u8]>, + ) -> Self::RevValuesIterator<'a>; + fn rev_pairs<'a>( + &'a self, + start: Option<&[u8]>, + end: Option<&[u8]>, + ) -> Self::RevPairsIterator<'a>; +} diff --git a/crates/storey/Cargo.toml b/crates/storey/Cargo.toml index 594778b..6db7c87 100644 --- a/crates/storey/Cargo.toml +++ b/crates/storey/Cargo.toml @@ -2,15 +2,18 @@ name = "storey" description = "Storage abstractions for blockchains" readme = "../../README.md" -authors = { workspace = true } -repository = { workspace = true } -homepage = { workspace = true } -categories = { workspace = true } -keywords = { workspace = true } version = "0.1.0" edition = "2021" rust-version = "1.65" # https://caniuse.rs/features/generic_associated_types -license = { workspace = true } +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +categories.workspace = true +keywords.workspace = true [dependencies] thiserror = "1" + +storey-encoding = { version = "0.1.0", path = "../storey-encoding" } +storey-storage = { version = "0.1.0", path = "../storey-storage" } diff --git a/crates/storey/src/containers/mod.rs b/crates/storey/src/containers/mod.rs index 0e0c6c1..315eed2 100644 --- a/crates/storey/src/containers/mod.rs +++ b/crates/storey/src/containers/mod.rs @@ -1,6 +1,7 @@ pub mod column; mod item; mod map; +mod test_mocks; use std::marker::PhantomData; diff --git a/crates/storey/src/containers/test_mocks.rs b/crates/storey/src/containers/test_mocks.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/crates/storey/src/containers/test_mocks.rs @@ -0,0 +1 @@ + diff --git a/crates/storey/src/encoding.rs b/crates/storey/src/encoding.rs index 2e602a8..0b311c2 100644 --- a/crates/storey/src/encoding.rs +++ b/crates/storey/src/encoding.rs @@ -94,10 +94,7 @@ /// A trait for types that serve as "markers" for a particular encoding. /// These types are expected to be empty structs. -pub trait Encoding { - type EncodeError; - type DecodeError; -} +pub use storey_encoding::Encoding; /// A trait for types that can be encoded with a particular encoding. /// @@ -109,9 +106,7 @@ pub trait Encoding { /// [See the module-level documentation for an example.](self) /// /// [sealed]: https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed -pub trait EncodableWith: sealed::SealedE { - fn encode(&self) -> Result, E::EncodeError>; -} +pub use storey_encoding::EncodableWith; /// A trait for implementing [`EncodableWith`] for a particular encoding. /// @@ -122,19 +117,7 @@ pub trait EncodableWith: sealed::SealedE { /// rules. /// /// [See the module-level documentation for usage.](self) - -pub trait EncodableWithImpl { - fn encode_impl(self) -> Result, E::EncodeError>; -} - -impl EncodableWith for T -where - for<'a> Cover<&'a T>: EncodableWithImpl, -{ - fn encode(&self) -> Result, ::EncodeError> { - Cover(self).encode_impl() - } -} +pub use storey_encoding::EncodableWithImpl; /// A trait for types that can be decoded with a particular encoding. /// @@ -146,9 +129,7 @@ where /// [See the module-level documentation for an example.](self) /// /// [sealed]: https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed -pub trait DecodableWith: Sized + sealed::SealedD { - fn decode(data: &[u8]) -> Result; -} +pub use storey_encoding::DecodableWith; /// A trait for implementing [`DecodableWith`] for a particular encoding. /// @@ -159,38 +140,7 @@ pub trait DecodableWith: Sized + sealed::SealedD { /// rules. /// /// [See the module-level documentation for usage.](self) - -pub trait DecodableWithImpl: Sized { - fn decode_impl(data: &[u8]) -> Result; -} - -impl DecodableWith for T -where - Cover: DecodableWithImpl, -{ - fn decode(data: &[u8]) -> Result::DecodeError> { - let wrapper = >::decode_impl(data)?; - Ok(wrapper.0) - } -} - -mod sealed { - // This module is private to the crate. It's used to seal the `EncodableWith` and - // `DecodableWith` traits, so that the only way they can be implemented outside - // this crate is through the blanket implementations provided by `EncodableWithImpl` - // and `DecodableWithImpl`. - // - // More information on sealed traits: - // https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed - - use super::*; - - pub trait SealedE {} - pub trait SealedD {} - - impl SealedE for T where for<'a> Cover<&'a T>: EncodableWithImpl {} - impl SealedD for T where Cover: DecodableWithImpl {} -} +pub use storey_encoding::DecodableWithImpl; /// A wrapper type used to [cover] type arguments when providing blanket implementations of /// [`EncodableWithImpl`] and [`DecodableWithImpl`]. @@ -205,4 +155,4 @@ mod sealed { /// /// [orphan rules]: https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules /// [cover]: https://doc.rust-lang.org/reference/glossary.html#uncovered-type -pub struct Cover(pub T); +pub use storey_encoding::Cover; diff --git a/crates/storey/src/storage/mod.rs b/crates/storey/src/storage/mod.rs index ec19ea2..c3e268d 100644 --- a/crates/storey/src/storage/mod.rs +++ b/crates/storey/src/storage/mod.rs @@ -1,106 +1,6 @@ -mod backend; mod branch; -pub use backend::{StorageBackend, StorageBackendMut}; pub use branch::StorageBranch; - -pub trait Storage { - fn get(&self, key: &[u8]) -> Option>; - - fn has(&self, key: &[u8]) -> bool { - self.get(key).is_some() - } - - fn get_meta(&self, _key: &[u8]) -> Option>; - fn has_meta(&self, key: &[u8]) -> bool { - self.get_meta(key).is_some() - } -} - -pub trait StorageMut { - fn set(&mut self, key: &[u8], value: &[u8]); - fn remove(&mut self, key: &[u8]); - - fn set_meta(&mut self, _key: &[u8], _value: &[u8]); - fn remove_meta(&mut self, _key: &[u8]); -} - -pub trait IterableStorage { - type KeysIterator<'a>: Iterator> - where - Self: 'a; - type ValuesIterator<'a>: Iterator> - where - Self: 'a; - type PairsIterator<'a>: Iterator, Vec)> - where - Self: 'a; - - fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a>; - fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a>; - fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a>; -} - -impl IterableStorage for &T { - type KeysIterator<'a> = T::KeysIterator<'a> where Self: 'a; - type ValuesIterator<'a> = T::ValuesIterator<'a> where Self: 'a; - type PairsIterator<'a> = T::PairsIterator<'a> where Self: 'a; - - fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a> { - (**self).keys(start, end) - } - - fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a> { - (**self).values(start, end) - } - - fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a> { - (**self).pairs(start, end) - } -} - -impl IterableStorage for &mut T { - type KeysIterator<'a> = T::KeysIterator<'a> where Self: 'a; - type ValuesIterator<'a> = T::ValuesIterator<'a> where Self: 'a; - type PairsIterator<'a> = T::PairsIterator<'a> where Self: 'a; - - fn keys<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::KeysIterator<'a> { - (**self).keys(start, end) - } - - fn values<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::ValuesIterator<'a> { - (**self).values(start, end) - } - - fn pairs<'a>(&'a self, start: Option<&[u8]>, end: Option<&[u8]>) -> Self::PairsIterator<'a> { - (**self).pairs(start, end) - } -} - -pub trait RevIterableStorage { - type RevKeysIterator<'a>: Iterator> - where - Self: 'a; - type RevValuesIterator<'a>: Iterator> - where - Self: 'a; - type RevPairsIterator<'a>: Iterator, Vec)> - where - Self: 'a; - - fn rev_keys<'a>( - &'a self, - start: Option<&[u8]>, - end: Option<&[u8]>, - ) -> Self::RevKeysIterator<'a>; - fn rev_values<'a>( - &'a self, - start: Option<&[u8]>, - end: Option<&[u8]>, - ) -> Self::RevValuesIterator<'a>; - fn rev_pairs<'a>( - &'a self, - start: Option<&[u8]>, - end: Option<&[u8]>, - ) -> Self::RevPairsIterator<'a>; -} +pub use storey_storage::{ + IterableStorage, RevIterableStorage, Storage, StorageBackend, StorageBackendMut, StorageMut, +}; From b01b3f4a77cde489824303bdbb598961ebcd3c34 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Mon, 15 Apr 2024 14:24:33 +0200 Subject: [PATCH 2/2] refactor: put mocks in the new `mocks` crate --- Cargo.toml | 2 ++ crates/mocks/Cargo.toml | 15 +++++++++++++++ .../tests/common => mocks/src}/backend.rs | 16 +++++++++++----- .../tests/common => mocks/src}/encoding.rs | 2 +- .../tests/common/mod.rs => mocks/src/lib.rs} | 2 -- crates/storey/Cargo.toml | 7 +++++-- crates/storey/tests/backend.rs | 6 ++---- crates/storey/tests/containers.rs | 6 ++---- crates/storey/tests/encoding.rs | 3 +-- 9 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 crates/mocks/Cargo.toml rename crates/{storey/tests/common => mocks/src}/backend.rs (92%) rename crates/{storey/tests/common => mocks/src}/encoding.rs (95%) rename crates/{storey/tests/common/mod.rs => mocks/src/lib.rs} (61%) diff --git a/Cargo.toml b/Cargo.toml index b81b5f3..24e18b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,5 @@ keywords = ["CosmWasm"] [workspace.dependencies] storey = { path = "crates/storey", version = "0.1" } +storey-encoding = { path = "crates/storey-encoding", version = "0.1" } +storey-storage = { path = "crates/storey-storage", version = "0.1" } diff --git a/crates/mocks/Cargo.toml b/crates/mocks/Cargo.toml new file mode 100644 index 0000000..5d29552 --- /dev/null +++ b/crates/mocks/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "mocks" +version = "0.1.0" +edition = "2021" +publish = false +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +categories.workspace = true +keywords.workspace = true + +[dependencies] +storey-encoding.workspace = true +storey-storage.workspace = true diff --git a/crates/storey/tests/common/backend.rs b/crates/mocks/src/backend.rs similarity index 92% rename from crates/storey/tests/common/backend.rs rename to crates/mocks/src/backend.rs index 85ade93..c34ccdd 100644 --- a/crates/storey/tests/common/backend.rs +++ b/crates/mocks/src/backend.rs @@ -1,6 +1,6 @@ use std::{cell::UnsafeCell, collections::BTreeMap}; -use storey::storage::IterableStorage as _; +use storey_storage::IterableStorage as _; // `UnsafeCell` is needed here to implement interior mutability. // https://doc.rust-lang.org/book/ch15-05-interior-mutability.html @@ -18,6 +18,12 @@ impl TestStorage { } } +impl Default for TestStorage { + fn default() -> Self { + Self::new() + } +} + // Safety: in each of the unsafe blocks in this file, we drop the reference to // the BTreeMap before the function returns, so we can guarantee that no two references // to it exist at the same time. @@ -25,14 +31,14 @@ impl TestStorage { // Moreover, we can further guarantee that the dereference is valid because the data // is always initialized during construction. -impl storey::storage::StorageBackend for TestStorage { +impl storey_storage::StorageBackend for TestStorage { fn get(&self, key: &[u8]) -> Option> { // Safety: see above unsafe { (*self.0.get()).get(key).cloned() } } } -impl storey::storage::StorageBackendMut for TestStorage { +impl storey_storage::StorageBackendMut for TestStorage { fn set(&mut self, key: &[u8], value: &[u8]) { // Safety: see above unsafe { @@ -48,7 +54,7 @@ impl storey::storage::StorageBackendMut for TestStorage { } } -impl storey::storage::IterableStorage for TestStorage { +impl storey_storage::IterableStorage for TestStorage { type KeysIterator<'a> = Box> + 'a>; type ValuesIterator<'a> = Box> + 'a>; type PairsIterator<'a> = Box, Vec)> + 'a>; @@ -92,7 +98,7 @@ impl storey::storage::IterableStorage for TestStorage { } } -impl storey::storage::RevIterableStorage for TestStorage { +impl storey_storage::RevIterableStorage for TestStorage { type RevKeysIterator<'a> = Box> + 'a>; type RevValuesIterator<'a> = Box> + 'a>; type RevPairsIterator<'a> = Box, Vec)> + 'a>; diff --git a/crates/storey/tests/common/encoding.rs b/crates/mocks/src/encoding.rs similarity index 95% rename from crates/storey/tests/common/encoding.rs rename to crates/mocks/src/encoding.rs index 9c4b91b..1d977aa 100644 --- a/crates/storey/tests/common/encoding.rs +++ b/crates/mocks/src/encoding.rs @@ -1,4 +1,4 @@ -use storey::encoding::{Cover, DecodableWithImpl, EncodableWithImpl, Encoding}; +use storey_encoding::{Cover, DecodableWithImpl, EncodableWithImpl, Encoding}; // An implementation of an encoding used for tests. // diff --git a/crates/storey/tests/common/mod.rs b/crates/mocks/src/lib.rs similarity index 61% rename from crates/storey/tests/common/mod.rs rename to crates/mocks/src/lib.rs index 7143d6f..7110a04 100644 --- a/crates/storey/tests/common/mod.rs +++ b/crates/mocks/src/lib.rs @@ -1,4 +1,2 @@ -#![allow(dead_code)] - pub mod backend; pub mod encoding; diff --git a/crates/storey/Cargo.toml b/crates/storey/Cargo.toml index 6db7c87..e85a4d0 100644 --- a/crates/storey/Cargo.toml +++ b/crates/storey/Cargo.toml @@ -15,5 +15,8 @@ keywords.workspace = true [dependencies] thiserror = "1" -storey-encoding = { version = "0.1.0", path = "../storey-encoding" } -storey-storage = { version = "0.1.0", path = "../storey-storage" } +storey-encoding.workspace = true +storey-storage.workspace = true + +[dev-dependencies] +mocks = { path = "../mocks" } diff --git a/crates/storey/tests/backend.rs b/crates/storey/tests/backend.rs index 237773c..4ef0214 100644 --- a/crates/storey/tests/backend.rs +++ b/crates/storey/tests/backend.rs @@ -1,12 +1,10 @@ -mod common; - #[test] fn storage_backend() { // TODO: split this into multiple tests? use storey::storage::{IterableStorage as _, RevIterableStorage as _, StorageMut as _}; - let mut storage = common::backend::TestStorage::new(); + let mut storage = mocks::backend::TestStorage::new(); storage.set(&[0], b"bar"); storage.set(&[1], b"baz"); @@ -105,7 +103,7 @@ fn storage_backend() { fn metadata() { use storey::storage::StorageMut as _; - let mut storage = common::backend::TestStorage::new(); + let mut storage = mocks::backend::TestStorage::new(); storage.set_meta(&[0], b"meta"); assert_eq!(storey::storage::StorageBackend::get(&storage, &[0]), None); diff --git a/crates/storey/tests/containers.rs b/crates/storey/tests/containers.rs index 8055b53..0c14790 100644 --- a/crates/storey/tests/containers.rs +++ b/crates/storey/tests/containers.rs @@ -1,10 +1,8 @@ -mod common; - use storey::containers::{Column, Item, IterableAccessor as _, Map}; use storey::storage::Storage as _; -use common::backend::TestStorage; -use common::encoding::TestEncoding; +use mocks::backend::TestStorage; +use mocks::encoding::TestEncoding; #[test] fn item() { diff --git a/crates/storey/tests/encoding.rs b/crates/storey/tests/encoding.rs index b05e204..c4c1584 100644 --- a/crates/storey/tests/encoding.rs +++ b/crates/storey/tests/encoding.rs @@ -1,5 +1,4 @@ -mod common; - +use mocks as _; use storey::encoding::{DecodableWith as _, EncodableWith as _}; #[test]