I'm working on a simple data store, and the type signature is getting complicated. The store needs to keep track of the data it's storing as well as a couple indexes. I'd like to be able to generic about how the data is stored so the underlying stores could be changed (ie in-memory vs RocksDB) or data expiration could be added (ie a LRU expiration).
One way of doing this would be to configure the backing stores as part of the type signature, like Database<Store<Value>, Index<Key, Value>>
, but this is getting ugly quickly as the number of related types grows. I could create a trait and use associated types, but that doesn't really simplify the call site. In Go (the language I spend most of my time writing) I'd just pass in a configuration object like DBConfig{Store: store, Index: index}
.
Are there other solutions that are more "idiomatic" Rust? How have you handled configuring complex groupings of interdependent types?