[][src]Module fxa_client::state_persistence

This module implements the ability to serialize a FirefoxAccount struct to and from a JSON string. The idea is that calling code will use this to persist the account state to storage.

Many of the details here are a straightforward use of serde, with all persisted data being a field on a State struct. This is, however, some additional complexity around handling data migrations - we need to be able to evolve the internal details of the State struct while gracefully handing users who are upgrading from an older version of a consuming app, which has stored account state from an older version of this component.

Data migration is handled by explicitly naming different versions of the state struct to correspond to different incompatible changes to the data representation, e.g. StateV1 and StateV2. We then wrap this in a PersistedState enum whose serialization gets explicitly tagged with the corresponding state version number.

For backwards-compatible changes to the data (such as adding a new field that has a sensible default) we keep the current State struct, but modify it in such a way that serde knows how to do the right thing.

For backwards-incompatible changes to the data (such as removing or significantly refactoring fields) we define a new StateV{X+1} struct, and use the From trait to define how to update from older struct versions.

Structs

StateV1
StateV2
V1AuthInfo
V1Config

Enums

PersistedState

Functions

state_from_json
state_to_json
upgrade_state

Type Definitions

State