Skip to content

Commit 24722cf

Browse files
committed
add better documentation about require_{indices,novelties}_tracking
1 parent b2791e4 commit 24722cf

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

libafl/src/observers/map.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ pub mod macros {
258258
/// As an example, if you are developing the type `MyCustomScheduler<O>` which requires novelty
259259
/// tracking, use this in your constructor:
260260
/// ```
261-
/// # use libafl::observers::TrackingHinted;
261+
/// # use libafl::observers::{MapObserver, TrackingHinted};
262262
/// # use libafl::require_index_tracking;
263263
/// # use core::marker::PhantomData;
264264
/// #
265-
/// # struct MyCustomScheduler<O> {
266-
/// # phantom: PhantomData<O>,
265+
/// # struct MyCustomScheduler<O, A> {
266+
/// # phantom: PhantomData<(O, A)>,
267267
/// # }
268268
/// #
269-
/// impl<O> MyCustomScheduler<O> where O: TrackingHinted {
270-
/// pub fn new() -> Self {
271-
/// require_index_tracking!("MyCustomScheduler", O);
269+
/// impl<O, A> MyCustomScheduler<O, A> where O: MapObserver, A: AsRef<O> + TrackingHinted {
270+
/// pub fn new(obs: &A) -> Self {
271+
/// require_index_tracking!("MyCustomScheduler", A);
272272
/// todo!("Construct your type")
273273
/// }
274274
/// }
@@ -309,17 +309,17 @@ pub mod macros {
309309
/// As an example, if you are developing the type `MyCustomScheduler<O>` which requires novelty
310310
/// tracking, use this in your constructor:
311311
/// ```
312-
/// # use libafl::observers::TrackingHinted;
312+
/// # use libafl::observers::{MapObserver, TrackingHinted};
313313
/// # use libafl::require_novelties_tracking;
314314
/// # use core::marker::PhantomData;
315315
/// #
316-
/// # struct MyCustomScheduler<O> {
317-
/// # phantom: PhantomData<O>,
316+
/// # struct MyCustomScheduler<O, A> {
317+
/// # phantom: PhantomData<(O, A)>,
318318
/// # }
319319
/// #
320-
/// impl<O> MyCustomScheduler<O> where O: TrackingHinted {
321-
/// pub fn new() -> Self {
322-
/// require_novelties_tracking!("MyCustomScheduler", O);
320+
/// impl<O, A> MyCustomScheduler<O, A> where O: MapObserver, A: AsRef<O> + TrackingHinted {
321+
/// pub fn new(obs: &A) -> Self {
322+
/// require_novelties_tracking!("MyCustomScheduler", A);
323323
/// todo!("Construct your type")
324324
/// }
325325
/// }
@@ -357,6 +357,14 @@ pub mod macros {
357357

358358
/// A [`MapObserver`] observes the static map, as oftentimes used for AFL-like coverage information
359359
///
360+
/// When referring to this type in a constraint (e.g. `O: MapObserver`), ensure that you only refer
361+
/// to instances of a second type, e.g. `A: AsRef<O>`. Map observer instances are passed around in
362+
/// a way that may be potentially wrapped by e.g. [`ExplicitTracking`] as a way to encode metadata
363+
/// into the type. This is an unfortunate additional requirement that we can't get around without
364+
/// specialization.
365+
///
366+
/// See [`crate::require_index_tracking`] for an example of how to do so.
367+
///
360368
/// TODO: enforce `iter() -> AssociatedTypeIter` when generic associated types stabilize
361369
pub trait MapObserver:
362370
HasLen + Named + Serialize + serde::de::DeserializeOwned + AsRef<Self>

0 commit comments

Comments
 (0)