| Crates.io | tuple_list_ex |
| lib.rs | tuple_list_ex |
| version | 0.15.4 |
| created_at | 2025-11-13 01:40:24.765535+00 |
| updated_at | 2025-11-13 01:40:24.765535+00 |
| description | Useful Haskel-like extensions for the tuple_list crate |
| homepage | |
| repository | https://github.com/AFLplusplus/LibAFL/ |
| max_upload_size | |
| id | 1930271 |
| size | 67,616 |
Tuple_List_Ex: Added functionality for tuple_listsThis crate adds handy features to the Haskel-like tuple_list crate.
It's part of the LibAFL project.
This crate provides a variety of traits that extend the functionality of tuple_list. Here are a few examples:
MatchFirstTypeGet the first element of a specific type from a tuple list.
use tuple_list::tuple_list;
use tuple_list_ex::MatchFirstType;
// Create a tuple list
let tuple = tuple_list!(1i32, "hello", 3.0f64);
// Get the first element of a specific type
let first_i32: Option<&i32> = tuple.match_first_type();
assert_eq!(first_i32, Some(&1));
let first_f64: Option<&f64> = tuple.match_first_type();
assert_eq!(first_f64, Some(&3.0));
Prepend, Append, and MergeModify tuple lists by adding elements or merging them.
use tuple_list::tuple_list;
use tuple_list_ex::{Prepend, Append, Merge};
let tuple = tuple_list!(1i32, "hello");
// Prepend an element
let prepended = tuple.prepend(true);
assert_eq!(prepended, (true, (1, ("hello", ()))));
// Append an element
let appended = prepended.append(3.0f64);
assert_eq!(appended, ((true, (1, ("hello", ()))), 3.0f64));
// Merge two tuple lists
let other_tuple = tuple_list!(4u8, 5u16);
let merged = prepended.merge(other_tuple);
assert_eq!(merged, (true, (1, ("hello", (4, (5, ()))))));
NamedTuple and MatchNameAccess elements by name for tuples containing Named elements.
# #[cfg(feature = "alloc")]
# {
use tuple_list::tuple_list;
use tuple_list_ex::{NamedTuple, MatchName};
use libafl_core::Named;
use std::borrow::Cow;
struct MyNamed {
name: &'static str,
}
impl Named for MyNamed {
fn name(&self) -> &Cow<'static, str> {
&self.name
}
}
let named_tuple = tuple_list!(MyNamed { name: "first" }, MyNamed { name: "second" });
// Get names
let names = named_tuple.names();
assert_eq!(names, vec!["first", "second"]);
// Get an element by name
let second: Option<&MyNamed> = named_tuple.match_name("second");
assert!(second.is_some());
assert_eq!(second.unwrap().name(), "second");
# }
This crate has the following features:
std: (Default) Enables features that require the standard library.alloc: (Default) Enables features that require allocation, like IntoVec and NamedTuple.serde: Enables serde support for Handle.Here is a list of the traits and functionality provided by this crate:
SplitBorrow: Borrows each member of the tuple, returning a new tuple of references.IntoVec: Converts a tuple list into a Vec.HasConstLen: Provides the length of the tuple list as a const usize.MatchFirstType: Gets the first element of a specific type.ExtractFirstRefType and ExtractFirstRefMutType: Takes the first element of a given type.SplitBorrowExtractFirstType: A combination of SplitBorrow and ExtractFirstRefType.MatchType: Applies a function to all elements of a specific type.NamedTuple: For tuples where each element has a name.MatchName: Finds an element by its name.Handled, Handle, MatchNameRef: A system for referencing tuple elements by a handle (name + type).GetAll: Retrieves multiple elements from a tuple list using a list of handles.RefIndexable: Allows indexing a tuple list with [] using handles.Prepend: Adds an element to the beginning of a tuple list.Append: Adds an element to the end of a tuple list.Merge: Merges two tuple lists.Map, MappingFunctor: Maps each element of a tuple list to a new type.tuple_for_each!: Iterates over a tuple.tuple_for_each_mut!: Iterates over a tuple with mutable access.map_tuple_list_type!: Gets the resulting type of a map operation.merge_tuple_list_type!: Gets the resulting type of a merge operation.LibAFL ProjectThe LibAFL project is part of AFLplusplus and maintained by
For bugs, feel free to open issues or contact us directly. Thank you for your support. <3
Even though we will gladly assist you in finishing up your PR, try to
cfgs.)cargo nightly fmt on your code before pushingcargo clippy --all or ./clippy.shcargo build --no-default-features to check for no_std compatibility (and possibly add #[cfg(feature = "std")]) to hide parts of your code.Some parts in this list may sound hard, but don't be afraid to open a PR if you cannot fix them by yourself. We will gladly assist.