iggy
iggy copied to clipboard
Refactor `Storage` trait
For example, the load()
method expects an empty struct to be passed to load the data, while it's not the case anymore for some components.
Seems that refactor to async fn load(&self) -> Result<T, Error>;
would be better?
Yes, this sounds good, ideally, the storage would just return the data and do not expect mutable struct passed into it to change its internal state. Most of the new methods already work in this way, but the older ones left intact.
Yes, this sounds good, ideally, the storage would just return the data and do not expect mutable struct passed into it to change its internal state. Most of the new methods already work in this way, but the older ones left intact.
I have the following suggestions for refactoring the Storage trait to make it more intuitive and extensible
pub trait WithKey {
type Key;
fn get_key(&self) -> &Self::Key;
}
#[async_trait]
pub trait NewStorage<T, K>: Sync + Send
where
T: WithKey<Key = K>,
{
async fn load(&self, key: &K) -> Result<(), Error>;
async fn save(&self, component: T) -> Result<(), Error>;
async fn delete(&self, key: &K) -> Result<(), Error>;
}
but it's a bit difficult to refactor, do you have any suggestions for step-by-step refactoring?