4 releases

Uses new Rust 2024

0.1.3 Jul 31, 2025
0.1.2 Jul 29, 2025
0.1.1 Jul 29, 2025
0.1.0 Jul 29, 2025

#1400 in Rust patterns

Download history 239/week @ 2025-07-27 22/week @ 2025-08-03 1/week @ 2025-08-17 3/week @ 2025-09-28 1/week @ 2025-10-05

120 downloads per month

MIT license

7KB
101 lines

QuickVariant

This library is designed with reference to C++'s std::variant, allowing you to create variants using only type names.

Warning

This library uses unsafe code. Please follow the usage guidelines carefully when using it. Rust's enum is extremely powerful, and in most cases, the functionality provided by this crate can be fully replaced by a simple enum.

Example

// Please be sure to initialize using quickvariant::macros::make_variant!.
let mut variant = quickvariant::macros::make_variant!(i32, u64, String);

unsafe {
    variant.set(String::from("Hello, World")).unwrap();
}

println!("{:#?}", variant.get::<String>().unwrap());

License

QuickVariant is licensed under the MIT license (see LICENSE in the main repository).

Dependencies

~165–580KB
~14K SLoC