wrapped-list 1.0.1

Macro for wrapping elements of a list with an object, function, or another macro at compile time
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 1 items with examples
  • Size
  • Source code size: 14.67 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hunterlawson/wrapped-list
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hunterlawson

wrapped-list

Build Crate License

This crate provides macros which allow you to create lists of elements that are wrappped by an object, function, or another macro at compile time. Check out the documentation.

wrapped_list![Box::new; value_1, value_2, ...]

Expands to:

[Box::new(value_1), Box::new(value_2), ...]

With this you can:

Examples

Wrap values with a tuple struct or enum

use wrapped_list::wrapped_list;

#[derive(Debug, PartialEq, Eq)]
struct Wrapper(i32);

let wrapped_items = wrapped_list![Wrapper; 1, 2, 3, 4];

assert_eq!(wrapped_items, [Wrapper(1), Wrapper(2), Wrapper(3), Wrapper(4)]);

Wrap values with an object or function

use wrapped_list::wrapped_list;

let boxed_items = wrapped_list![Box::new; 1, 2, 3];

assert_eq!(boxed_items, [Box::new(1), Box::new(2), Box::new(3)])
use wrapped_list::wrapped_list;

let func = |x| x * 2;

let doubled = wrapped_list![func; 1, 2, 3];

assert_eq!(doubled, [2, 4, 6]);

Wrap values with a macro

use wrapped_list::wrapped_list;

macro_rules! add_one {
    ($e:expr) => {
        $e + 1
    };
}

let one_more = wrapped_list![add_one!; 1, 2, 3];

assert_eq!(one_more, [2, 3, 4]);