Skip to content

Commit

Permalink
refactor: less awkward associated type names
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed May 8, 2024
1 parent 1a7cb1f commit 4c43181
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions packages/storey/src/containers/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
E: Encoding,
T: EncodableWith<E> + DecodableWith<E>,
{
type AccessorT<S> = ColumnAccess<E, T, S>;
type Accessor<S> = ColumnAccess<E, T, S>;
type Key = u32;
type KeyDecodeError = ColumnKeyDecodeError;
type Value = T;
Expand Down Expand Up @@ -127,10 +127,10 @@ where
T: EncodableWith<E> + DecodableWith<E>,
S: IterableStorage,
{
type StorableT = Column<T, E>;
type StorageT = S;
type Storable = Column<T, E>;
type Storage = S;

fn storage(&self) -> &Self::StorageT {
fn storage(&self) -> &Self::Storage {
&self.storage
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/storey/src/containers/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
E: Encoding,
T: EncodableWith<E> + DecodableWith<E>,
{
type AccessorT<S> = ItemAccess<E, T, S>;
type Accessor<S> = ItemAccess<E, T, S>;
type Key = ();
type KeyDecodeError = ItemKeyDecodeError;
type Value = T;
Expand Down
12 changes: 6 additions & 6 deletions packages/storey/src/containers/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
V: Storable,
<V as Storable>::KeyDecodeError: std::fmt::Display,
{
type AccessorT<S> = MapAccess<K, V, S>;
type Accessor<S> = MapAccess<K, V, S>;
type Key = (K, V::Key);
type KeyDecodeError = MapKeyDecodeError<V::KeyDecodeError>;
type Value = V::Value;
Expand Down Expand Up @@ -183,7 +183,7 @@ where
///
/// assert_eq!(access.entry("foo").entry("bar").get().unwrap(), None);
/// ```
pub fn entry<Q>(&self, key: &Q) -> V::AccessorT<StorageBranch<&S>>
pub fn entry<Q>(&self, key: &Q) -> V::Accessor<StorageBranch<&S>>
where
K: Borrow<Q>,
Q: Key + ?Sized,
Expand Down Expand Up @@ -222,7 +222,7 @@ where
/// access.entry_mut("foo").entry_mut("bar").set(&1337).unwrap();
/// assert_eq!(access.entry("foo").entry("bar").get().unwrap(), Some(1337));
/// ```
pub fn entry_mut<Q>(&mut self, key: &Q) -> V::AccessorT<StorageBranch<&mut S>>
pub fn entry_mut<Q>(&mut self, key: &Q) -> V::Accessor<StorageBranch<&mut S>>
where
K: Borrow<Q>,
Q: Key + ?Sized,
Expand Down Expand Up @@ -256,10 +256,10 @@ where
<V as Storable>::KeyDecodeError: std::fmt::Display,
S: IterableStorage,
{
type StorableT = Map<K, V>;
type StorageT = S;
type Storable = Map<K, V>;
type Storage = S;

fn storage(&self) -> &Self::StorageT {
fn storage(&self) -> &Self::Storage {
&self.storage
}
}
Expand Down
34 changes: 17 additions & 17 deletions packages/storey/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Storable {
/// specific [`Storage`] type used (the `S` type parameter here).
///
/// [`Storage`]: crate::storage::Storage
type AccessorT<S>;
type Accessor<S>;

/// The Key type for this collection/container. This is the type that will be used in
/// key iteration.
Expand All @@ -44,7 +44,7 @@ pub trait Storable {
/// Create an accessor for this collection/container, given a [`Storage`] implementation.
///
/// [`Storage`]: crate::storage::Storage
fn access_impl<S>(storage: S) -> Self::AccessorT<S>;
fn access_impl<S>(storage: S) -> Self::Accessor<S>;

/// Decode a key from a byte slice.
///
Expand All @@ -70,34 +70,34 @@ pub enum KVDecodeError<K, V> {
/// their contents.
pub trait IterableAccessor: Sized {
/// The [`Storable`] type this accessor is associated with.
type StorableT: Storable;
type Storable: Storable;

/// The [`Storage`] type this accessor is associated with.
///
/// [`Storage`]: crate::storage::Storage
type StorageT: IterableStorage;
type Storage: IterableStorage;

/// Get a reference to the storage this accessor is associated with.
fn storage(&self) -> &Self::StorageT;
fn storage(&self) -> &Self::Storage;

/// Iterate over key-value pairs in this collection.
fn pairs(&self) -> StorableIter<'_, Self::StorableT, Self::StorageT> {
fn pairs(&self) -> StorableIter<'_, Self::Storable, Self::Storage> {
StorableIter {
inner: self.storage().pairs(None, None),
phantom: PhantomData,
}
}

/// Iterate over keys in this collection.
fn keys(&self) -> StorableKeys<'_, Self::StorableT, Self::StorageT> {
fn keys(&self) -> StorableKeys<'_, Self::Storable, Self::Storage> {
StorableKeys {
inner: self.storage().keys(None, None),
phantom: PhantomData,
}
}

/// Iterate over values in this collection.
fn values(&self) -> StorableValues<'_, Self::StorableT, Self::StorageT> {
fn values(&self) -> StorableValues<'_, Self::Storable, Self::Storage> {
StorableValues {
inner: self.storage().values(None, None),
phantom: PhantomData,
Expand All @@ -111,10 +111,10 @@ pub trait BoundedIterableAccessor: IterableAccessor {
&self,
start: Option<S>,
end: Option<E>,
) -> StorableIter<'_, Self::StorableT, Self::StorageT>
) -> StorableIter<'_, Self::Storable, Self::Storage>
where
S: BoundFor<Self::StorableT>,
E: BoundFor<Self::StorableT>,
S: BoundFor<Self::Storable>,
E: BoundFor<Self::Storable>,
{
let start = start.map(|b| b.into_bytes());
let end = end.map(|b| b.into_bytes());
Expand All @@ -130,10 +130,10 @@ pub trait BoundedIterableAccessor: IterableAccessor {
&self,
start: Option<S>,
end: Option<E>,
) -> StorableKeys<'_, Self::StorableT, Self::StorageT>
) -> StorableKeys<'_, Self::Storable, Self::Storage>
where
S: BoundFor<Self::StorableT>,
E: BoundFor<Self::StorableT>,
S: BoundFor<Self::Storable>,
E: BoundFor<Self::Storable>,
{
let start = start.map(|b| b.into_bytes());
let end = end.map(|b| b.into_bytes());
Expand All @@ -149,10 +149,10 @@ pub trait BoundedIterableAccessor: IterableAccessor {
&self,
start: Option<S>,
end: Option<E>,
) -> StorableValues<'_, Self::StorableT, Self::StorageT>
) -> StorableValues<'_, Self::Storable, Self::Storage>
where
S: BoundFor<Self::StorableT>,
E: BoundFor<Self::StorableT>,
S: BoundFor<Self::Storable>,
E: BoundFor<Self::Storable>,
{
let start = start.map(|b| b.into_bytes());
let end = end.map(|b| b.into_bytes());
Expand Down

0 comments on commit 4c43181

Please sign in to comment.