I have a standard configuration system in my rust project. There’s a struct representing a “configuration profile”. On startup all the serialized profiles within a directory parsed and loaded as a vector of this struct using serde
, and then serialized again once changes are made.
If I ever want to introduce new features which will require additional fields in the profile config files, the already existing configuration files of users who previously installed the app will not be loadable as they will be missing fields.
What methods exist for handling such migrations?
- I can’t make all new fields
Option<T>
because that will introduce a lot of inconsistency in the source code. - I can’t configure
serde
to use theDefault
trait for missing fields because the default values for those fields are dynamically generated for each user based on the profile type and depending on their system. - Multiple issues regarding the topic in the
serde
repo already exist: https://github.com/serde-rs/serde/issues/1652, https://github.com/serde-rs/serde/issues/1986
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5