MCPcopy Index your code
hub / github.com/cofibrant/obake

github.com/cofibrant/obake @1.0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.0.5 ↗ · + Follow
102 symbols 156 edges 16 files 3 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build Issues crates.io License

お化け

Obake

Versioned data-structures for Rust.



<a href="https://docs.rs/obake/"><strong>View on docs.rs »</strong></a>

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:

[dependencies]
obake = "1.0"

Example

#[obake::versioned]                 // create a versioned data-structure
#[obake(version("0.1.0"))]          // declare some versions
#[obake(version("0.2.0"))]
#[derive(Debug, PartialEq, Eq)]     // additional attributes are applied to all versions
struct Foo {
    #[obake(cfg("0.1.0"))]          // enable fields for specific versions with
    foo: String,                    // semantic version constraints

    #[obake(cfg(">=0.2, <=0.3.0"))] // any semantic version constraint can appear in
    bar: u32,                       // a `cfg` attribute 

    #[obake(cfg("0.1.0"))]          // multiple `cfg` attributes are treated as a
    #[obake(cfg(">=0.3"))]          // disjunction over version constraints
    baz: char,
}

// describe migrations between versions using the `From` trait
// and an automatically generated type-level macro for referring to
// specific versions of `Foo`
impl From<Foo!["0.1.0"]> for Foo!["0.2.0"] {
    fn from(foo: Foo!["0.1.0"]) -> Self {
        Self { bar: 0 }
    }
}

// an enumeration of all versions of `Foo` is accessed using the `obake::AnyVersion` type
// alias
let versioned_example: obake::AnyVersion<Foo> = (Foo { bar: 42 }).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!(example, Foo { bar: 42 });

Other Features

  • #[obake(inherit)]: allows nesting of versioned data-structures.
  • #[obake(derive(...))]: allows derive attributes to be applied to generated enums.
  • #[obake(serde(...))]: allows serde attributes to be applied to generated enums.
  • Note: requires the feature serde.

Limitations

  • Cannot be applied to tuple structs (or enum variants with unnamed fields).
  • Cannot be applied to items with generic parameters.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Obake by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

Versioned (Interface)
Automatically implemented for the latest version of a versioned data-structure. ## Note Not intended to be hand-implem
obake/src/lib.rs
VersionExt (Interface)
(no doc) [1 implementers]
obake_macros/src/expand.rs
VersionTagged (Interface)
Automatically implemented by the generated version-tagged encoding of a [`versioned`] data-structure. ## Note Not inte
obake/src/lib.rs
VersionOf (Interface)
Automatically implemented for all declared versions of a versioned data-structure. ## Note Not intended to be hand-imp
obake/src/lib.rs

Core symbols most depended-on inside this repo

ident
called by 9
obake_macros/src/internal.rs
obake
called by 5
obake_macros/src/internal.rs
versions
called by 5
obake_macros/src/internal.rs
version
called by 5
obake_macros/src/expand.rs
versioned_ident
called by 5
obake_macros/src/expand.rs
inherits
called by 4
obake_macros/src/internal.rs
expand_variants
called by 4
obake_macros/src/expand.rs
cfgs
called by 3
obake_macros/src/internal.rs

Shape

Method 38
Class 31
Enum 16
Function 13
Interface 4

Languages

Rust100%

Modules by API surface

obake_macros/src/internal.rs35 symbols
obake_macros/src/expand.rs17 symbols
obake/tests/ui/bad_helpers.rs6 symbols
obake/tests/ui/bad_attrs.rs6 symbols
obake/tests/ui/semver.rs5 symbols
obake/tests/ui/generics.rs5 symbols
obake/tests/ui/bad_inherits.rs4 symbols
obake/tests/migrations.rs4 symbols
obake/tests/derive.rs4 symbols
obake/src/lib.rs4 symbols
obake/tests/ui/no_version.rs3 symbols
obake/tests/ui/duplicate_version.rs3 symbols

For agents

$ claude mcp add obake \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact