Module vmcore::save_restore
source · Expand description
Traits and types for save/restore support.
To implement save/restore for your device or state unit, you must do these things:
-
You define a saved state type. This type needs to be stable across releases, so you should not share types with your implementation even if they are currently identical. By decoupling your runtime types and your saved state types, you are much less likely to accidentally break saved state compatibility.
-
derive
some traits on your type. Specifically, you must deriveProtobuf
so that your type can be encoded into protobuf format, and any fields in your type must also implementProtobuf
.So that your saved state type can show up in generated
.proto
files, you must also set an attribute#[mesh(package = "my.package.name")]
. This specifies the protobuf package, as well as the file name of your protobuf file. For the root object of your device’s saved state, this package name becomes part of the serialized state, so you cannot change it later.Finally, in the root object of your saved state, you must additionally derive
SavedStateRoot
. This provides some additional metadata so that we can find your saved state type and generate a.proto
file from it for analysis. You only need to put this on the root types or types that will be converted toSavedStateBlob
; the infrastructure will find any dependent types. But it doesn’t hurt to put it on other types, too. -
Typically, you implement the
SaveRestore
trait. This trait allows you to specify your associated saved state type and to implementsave
andrestore
methods that act on this type.For some device types (such as vmbus devices), you may need to use a device-specific trait that provides additional parameters. But the pattern should be the same.
Structs§
- Convenience type for objects that have no saved state.
- An opaque saved state blob, encoded as a protobuf message.
Enums§
- A save operation error.
- A restore error.
- A save error.
- Convenience type for objects that do not support being saved.
Traits§
- Trait implemented by objects that implement
SaveRestore
with an associated type that can be serialized as a protobuf message. - Implemented by objects which can be saved/restored
- Trait implemented by “root” saved state blobs, which are ones that either form the root of a saved state tree, or at points in the tree where the type is not known at compile time.
Functions§
- Gets the message descriptions for all types deriving
SavedStateRoot
.
Derive Macros§
- Derives
SavedStateRoot
for a type.