Giter Site home page Giter Site logo

yumemi-inc / frunk-enum Goto Github PK

View Code? Open in Web Editor NEW

This project forked from metaswitch/frunk-enum

0.0 2.0 0.0 53 KB

Extensions to frunk (https://github.com/lloydmeta/frunk) to allow transmogrification of `enum` types

License: Other

Rust 100.00%

frunk-enum's Introduction

Frunk Enum Support

Warning
This fork was for supporting frunk v0.4 and won't be maintained anymore. See Metaswitch#31 .

Crates.io - frunk-enum Build Status License: MIT/APACHE-2.0

Usage

These crates augment the frunk crate to allow transmogrification of enums as well as structs. For more information on transmogrification and the LabelledGeneric trait it's based around, see https://docs.rs/frunk/latest/frunk/#transmogrifying and https://docs.rs/frunk/latest/frunk/labelled/trait.LabelledGeneric.html.

To take advantage of this feature for your own enum you need to:

  • Add the frunk-enum-derive crate to your Cargo.toml

  • Mark the enum with the custom derive:

    #[derive(LabelledGenericEnum)]
    enum Foo {
        Bar(String),
        Baz { name: String, id: Identity },
    }
    
  • Add the frunk-enum-core and frunk-core crates to your Cargo.toml

  • Then (assuming there's a NewFoo enum with the same structure as Foo) you can write:

    let foo = Foo::Baz { name: "Andy".into(), id: Identity };
    let new_foo: NewFoo = foo.transmogrify();
    

This works by deriving an implementation of LabelledGeneric for Foo which allows conversion to and from an instance of a generic sum-type. The core crate provides tools for converting between these generic sum-types where the bodies of the variants are recursively transmogrifiable. This allows for arbitrarily deep conversion between types, especially useful where the two types in question are autogenerated from some common input file, but are deemed to be different types by the rust compiler (e.g. because they're in separate crates).

Contributing

Thank you for your interest in frunk-enum, all contributions are welcome whether they be reports of issues, feature requests or code contributions.

Issue Contribution

When opening issues please provide a description of the issue, the version of frunk and frunk-enum plus example code which exhibits the issue.

Code Contribution

If you wish to contribute code to frunk-enum, you are welcome to do so using a github pull request, however you will need to sign each commit, to indicate that you are abiding to the terms of the DCO.

frunk-enum's People

Contributors

bossmc avatar bors[bot] avatar siketyan avatar richardwhiuk avatar dependabot-preview[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.