Implement ObjectStore
for trait objects
#3865
Labels
enhancement
Any new improvement worthy of a entry in the changelog
object-store
Object Store Interface
Motivation
I'm writing an application that will use Amazon S3 for long-term storage. I want to also use local file system during development. I'd like to make this configurable: it should be possible to choose the kind of storage at runtime, based on user input.
AWS CLI is one well-known application that would clearly benefit from doing this.
Problem
Generics are common in Rust.
object_store
itself providesPrefixObjectStore
that expects aT: ObjectStore
value.Unfortunately there's no (safe?) way to go back from a trait object to an owned value that implements the trait. That is, unless trait objects explicitly implement the trait.
Solution
impl ObjectStore for Box<dyn ObjectStore>
See #3866
Alternatives
Not sure. For wrappers provided by
object_store
itself it might be possible to haveObjectStore
provide combinators that return them.
Another approach that only really works for sealed traits is creating an enum that includes all possible trait implementations as variants.
The text was updated successfully, but these errors were encountered: