How to simplify complex type signatures


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?


Probably you know about this already, but maybe you’re looking for:


was recently closed, but not because we don’t want it. But that should help as well.

Hmm, I would imagine that it would, or at least, it wouldn’t of creation, but would when you’re later using it.