About
Obake is a procedural macro for declaring and maintaining versioned data-structures. The name 'obake' is taken from the Japanese 'お化け (おばけ)', a class of supernatural beings in Japanese folklore that shapeshift.
When developing an application, configuration formats and internal data-structures typically evolve between versions. However, maintaining backwards compatibility between these versions requires declaring and maintaining data-structures for legacy formats and code for migrating between them. Obake aims to make this process effortless.
Getting Started
To get started, add the following to your Cargo.toml
file:
[]
= "1.0"
Example
// create a versioned data-structure
// declare some versions
// additional attributes are applied to all versions
// describe migrations between versions using the `From` trait
// and an automatically generated type-level macro for referring to
// specific versions of `Foo`
// an enumeration of all versions of `Foo` is accessed using the `obake::AnyVersion` type
// alias
let versioned_example: AnyVersion = .into;
// this enumeration implements `Into<Foo>`, where `Foo` is the latest declared
// version of `Foo` (in this case, `Foo!["0.2.0"]`)
let example: Foo = versioned_example.into;
assert_eq!;
Other Features
#[obake(inherit)]
: allows nesting of versioned data-structures.#[obake(derive(...))]
: allows derive attributes to be applied to generated enums.#[obake(serde(...))]
: allowsserde
attributes to be applied to generatedenum
s.- Note: requires the feature
serde
.
- Note: requires the feature
Limitations
- Cannot be applied to tuple structs (or enum variants with unnamed fields).
- Cannot be applied to items with generic parameters.