Expand description
Compiletime lists/tuples used throughout the LibAFL universe
§Tuple_List_Ex: Added functionality for tuple_lists
This crate adds handy features to the Haskel-like tuple_list crate.
It’s part of the LibAFL project.
§Usage
This crate provides a variety of traits that extend the functionality of tuple_list. Here are a few examples:
§MatchFirstType
Get 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 Merge
Modify 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 MatchName
Access elements by name for tuples containing Named elements.
use tuple_list::tuple_list;
use tuple_list_ex::{NamedTuple, MatchName};
use libafl_core::Named;
use std::borrow::Cow;
struct MyNamed {
name: Cow<'static, str>,
}
impl Named for MyNamed {
fn name(&self) -> &Cow<'static, str> {
&self.name
}
}
let named_tuple = tuple_list!(MyNamed { name: Cow::Borrowed("first") }, MyNamed { name: Cow::Borrowed("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");§Features
This crate has the following features:
std: (Default) Enables features that require the standard library.alloc: (Default) Enables features that require allocation, likeIntoVecandNamedTuple.serde: Enablesserdesupport forHandle.
§Provided Traits and Functionality
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 aVec.HasConstLen: Provides the length of the tuple list as a constusize.MatchFirstType: Gets the first element of a specific type.ExtractFirstRefTypeandExtractFirstRefMutType: Takes the first element of a given type.SplitBorrowExtractFirstType: A combination ofSplitBorrowandExtractFirstRefType.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.- Macros:
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.
§The LibAFL Project
The LibAFL project is part of AFLplusplus and maintained by
- Andrea Fioraldi andrea@aflplus.plus
- Dominik Maier dominik@aflplus.plus
- s1341 github@shmarya.net
- Dongjia Zhang toka@aflplus.plus
- Addison Crump me@addisoncrump.info
§Contributing
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
- keep all the crates compiling with stable rust (hide the eventual non-stable code under
cfgs.) - run
cargo nightly fmton your code before pushing - check the output of
cargo clippy --allor./clippy.sh - run
cargo build --no-default-featuresto check forno_stdcompatibility (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.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies under more restrictive licenses, such as GPL or AGPL, can be enabled using the respective feature in each crate when it is present, such as the 'agpl' feature of the libafl crate.
§Feature Flags
§General Features
std(enabled by default) — Enables features that need rust’sstdlib to work, like print, env, … supportalloc(enabled by default) — Enables all features that allocate inno_stdserde— Enables serde support for tuple lists
Macros§
- map_
tuple_ list_ type - Maps the types of a mapping with a
MappingFunctor - merge_
tuple_ list_ type - Merges the types of two merged
tuple_list!s - tuple_
for_ each - Iterate over a tuple, executing the given
exprfor each element. - tuple_
for_ each_ mut - Iterate over a tuple, executing the given
exprfor each element, granting mut access. - tuple_
list - Macro creating tuple list values from list of expressions.
- tuple_
list_ type - Macro creating tuple list types from list of element types.
Structs§
- Handle
- Object with the type T and the name associated with its concrete value
- RefIndexable
- A wrapper type to enable the indexing of
MatchNameimplementors with[].
Traits§
- Append
- Append to a tuple
- Extract
First RefMut Type - Returns the first element with the given type (dereference mut version)
- Extract
First RefType - Returns the first element with the given type (dereference mut version)
- GetAll
- Get multiple values using a tuple of handles
- Handled
- Structs that have a
Handleto reference this element by, in maps. You should use this when you want to avoid specifying types. - HasConst
Len - Gets the length of the element
- Inner
Borrow Mut - Returns a mutably borrowed element
- IntoVec
- Create a
Vecfrom a tuple list or similar (We need this trait since we cannot implementIntofor foreign types) - Map
- Map all entries in a tuple to another type, dependent on the tail type.
- Mapping
Functor - Trait for structs which are capable of mapping a given type to another.
- Match
First Type - Returns the first element with the given type
- Match
Name - Match for a name and return the value
- Match
Name Ref - Search using
Handle - Match
Type - Match by type
- Merge
- Merge two
TupleList - Named
Tuple - A named tuple
- Prepend
- Allows prepending of values to a tuple
- Split
Borrow - Borrow each member of the tuple
- Split
Borrow Extract First Type - Borrow each member of the tuple
- Tuple
List - Trait providing conversion from tuple list into tuple.
Functions§
- type_eq
- Returns if the type
Tis equal toU, ignoring lifetimes.