Crate fed [] [src]

Anonymous, type-based, tagged type unions (here termed 'type federations') in stable Rust

Setup

In your crate root, include the crate aliased to _fed (since you'll rely on the init_fed! macro to declare the fed module):

#[macro_use]
extern crate fed as _fed;

Then, define all of the fed traits in your crate with this macro call:

init_fed!();

To actually use a type federation, you'll need to implement the type federation traits for all the concrete types you want to comprise the federation, via the fed! macro:

use fed::*;

fed!(String, bool, u8, Vec<i32>);

fn main() {
    let var: Fed4<String, bool, u8, Vec<i32>> = 33.into();
    assert!(var.is::<u8>());
}

For the time being, notice that we unfortunately will need to use everything in the fed module anywhere we want to use type federations. If this crate sees any use where this is an issue, I might work on fixing that. But this is largely intended for prototyping the feature to determine whether a fully fledged, built-in version would be useful for Rust to have.

Macros

basic_fed
fed

Macro to implement type federation traits for federations of concrete types

fed2
fed3
fed4
fed5
fed6
fed7
fed8
fed_promotion
fed_traits
from_fed
init_fed

Setup macro to be called after including the fed crate