breakdance

Crates.iobreakdance
lib.rsbreakdance
version0.0.3
sourcesrc
created_at2023-09-28 05:38:50.853294
updated_at2023-09-28 06:11:20.937925
descriptionExperimental macro for creating compile-time heterogeneously-typed collections
homepage
repositoryhttps://github.com/j-stach/breakdance.git
max_upload_size
id985577
size13,125
(j-stach)

documentation

README

breakdance

This is an experiment with macros to trick Rust collections into supporting heterogeneous types.

This macro provides support for heterogeneous lists by storing types within a Breakdown enum. This enum is procedurally generated by parsing occurrences of breakdown!() from the source code and creating an enum variant to reflect the type. The inner value can be retrieved with the .inner(), .inner_ref(), and .inner_mut() methods for Breakdown.

As of right now, you still need to specify the expected type when accessing the inner, so iterating over inner values is not possible unless they all share a trait. Trait implementation for Breakdown variants is possible but difficult at this time; future development may see the expansion of such additional features, but for now I am focusing on debugging.

This is just a toy project to give myself some more familiarity with the full set of Rust tools, but if anyone would like to give it a try in code please do! If you run into trouble getting it to work, please leave an issue on the GitHub repo (https://github.com/j-stach/breakdance).

Any other questions or suggestions are welcome too! Send me a message on GitHub.

How to use

Add it to your project:

cargo add breakdancer

And it should work like this:

use breakdance::*;

#[breakdance]
// submod declarations

fn main() {
    let num = breakdown!(42u8);
    let tru = breakdown!(true);

    let vec: Vec<Breakdown> = vec![num, tru];

    let num: &u8 = vec[0].inner_ref();
    println![ "{}", num ];    // prints 42
    let tru: &mut bool = vec[1].inner_mut();
    *tru = false;
    println![ "{}", tru ];    // prints false

}
Commit count: 25

cargo fmt