1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# Maintaining backwards compatability
If you change your structs, you probably want to be able to interact with data generated by previous versions of your structs. This section explains how you can do that.
For the purpose of this section, any field of type `std::optional`, `std::shared_ptr` or `std::unique_ptr` is an optional field. Any other fields are required.
Please refer to the section on optional fields for details.
## Rules
The following rules apply:
- You *can* add optional fields.
- You *can* remove any optional or required fields, if they are no longer needed.
- You *can* change the field names of any optional fields.
- You *can* change the order of any existing fields.
- You *can not* add any required fields.
- You *can not* change the field names of any required fields.
## API versioning
If you find it difficult to follow the rules as stated above or you cannot guarantee that you
will always be able to follow them in the future, you might want to use API versioning.
You can either use `rfl::TaggedUnion` or externally tagged variants:
```cpp
struct API_v_1_0 {
using Tag = rfl::Literal<"v1.0">;
...
};
struct API_v_1_1 {
using Tag = rfl::Literal<"v1.1">;
...
};
...
using APIs = rfl::TaggedUnion<"version", API_v_1_0, API_v_1_1, ...>;
```
```cpp
struct API_v_1_0 {
...
};
struct API_v_1_1 {
...
};
...
using APIs = rfl::Variant<rfl::Field<"v1.0", API_v_1_0>, rfl::Field<"v1.1", API_v_1_1>, ...>;
```
|