tuple_for_each

Crates.iotuple_for_each
lib.rstuple_for_each
version0.1.0
sourcesrc
created_at2024-07-17 05:49:28.505319
updated_at2024-07-17 05:49:28.505319
descriptionProvides macros and methods to iterate over the fields of a tuple struct
homepagehttps://github.com/arceos-org/arceos
repositoryhttps://github.com/arceos-org/tuple_for_each
max_upload_size
id1305848
size11,164
core (github:arceos-org:core)

documentation

https://docs.rs/tuple_for_each

README

tuple_for_each

crates.io Docs.rs CI

Provides macros and methods to iterate over the fields of a tuple struct.

Added methods:

  • is_empty() -> bool: Whether the tuple has no field.
  • len() -> usize: Number of items in the tuple.

Generated macros:

  • <tuple_name>_for_each!(x in tuple { ... })
  • <tuple_name>_enumerate!((i, x) in tuple { ... })

Examples

use tuple_for_each::TupleForEach;

#[derive(TupleForEach)]
struct FooBar(u32, &'static str, bool);

let tup = FooBar(23, "hello", true);
assert!(!tup.is_empty());
assert_eq!(tup.len(), 3);

// prints "23", "hello", "true" line by line
foo_bar_for_each!(x in tup {
    println!("{}", x);
});

// prints "0: 23", "1: hello", "2: true" line by line
foo_bar_enumerate!((i, x) in tup {
    println!("{}: {}", i, x);
});
Commit count: 0

cargo fmt