Skip to content

Commit ff33d7a

Browse files
committed
asref isn't reflexive??
1 parent b778a85 commit ff33d7a

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

libafl/src/observers/map.rs

+66-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ pub mod macros {
358358
/// A [`MapObserver`] observes the static map, as oftentimes used for AFL-like coverage information
359359
///
360360
/// TODO: enforce `iter() -> AssociatedTypeIter` when generic associated types stabilize
361-
pub trait MapObserver: HasLen + Named + Serialize + serde::de::DeserializeOwned
361+
pub trait MapObserver:
362+
HasLen + Named + Serialize + serde::de::DeserializeOwned + AsRef<Self>
362363
// where
363364
// for<'it> &'it Self: IntoIterator<Item = &'it Self::Entry>
364365
{
@@ -639,6 +640,15 @@ where
639640
}
640641
}
641642

643+
impl<'a, T, const DIFFERENTIAL: bool> AsRef<Self> for StdMapObserver<'a, T, DIFFERENTIAL>
644+
where
645+
T: Default + Copy + 'static + Serialize,
646+
{
647+
fn as_ref(&self) -> &Self {
648+
self
649+
}
650+
}
651+
642652
impl<'a, T, const DIFFERENTIAL: bool> MapObserver for StdMapObserver<'a, T, DIFFERENTIAL>
643653
where
644654
T: Bounded
@@ -1123,6 +1133,15 @@ where
11231133
}
11241134
}
11251135

1136+
impl<'a, T, const N: usize> AsRef<Self> for ConstMapObserver<'a, T, N>
1137+
where
1138+
T: Default + Copy + 'static + Serialize,
1139+
{
1140+
fn as_ref(&self) -> &Self {
1141+
self
1142+
}
1143+
}
1144+
11261145
impl<'a, T, const N: usize> MapObserver for ConstMapObserver<'a, T, N>
11271146
where
11281147
T: Bounded
@@ -1435,6 +1454,15 @@ where
14351454
}
14361455
}
14371456

1457+
impl<'a, T> AsRef<Self> for VariableMapObserver<'a, T>
1458+
where
1459+
T: Default + Copy + 'static + Serialize + PartialEq + Bounded,
1460+
{
1461+
fn as_ref(&self) -> &Self {
1462+
self
1463+
}
1464+
}
1465+
14381466
impl<'a, T> MapObserver for VariableMapObserver<'a, T>
14391467
where
14401468
T: Bounded
@@ -1689,6 +1717,15 @@ where
16891717
}
16901718
}
16911719

1720+
impl<M> AsRef<Self> for HitcountsMapObserver<M>
1721+
where
1722+
M: MapObserver<Entry = u8>,
1723+
{
1724+
fn as_ref(&self) -> &Self {
1725+
self
1726+
}
1727+
}
1728+
16921729
impl<M> MapObserver for HitcountsMapObserver<M>
16931730
where
16941731
M: MapObserver<Entry = u8>,
@@ -1938,6 +1975,16 @@ where
19381975
}
19391976
}
19401977

1978+
impl<M> AsRef<Self> for HitcountsIterableMapObserver<M>
1979+
where
1980+
M: MapObserver<Entry = u8>,
1981+
for<'it> M: AsIterMut<'it, Item = u8>,
1982+
{
1983+
fn as_ref(&self) -> &Self {
1984+
self
1985+
}
1986+
}
1987+
19411988
impl<M> MapObserver for HitcountsIterableMapObserver<M>
19421989
where
19431990
M: MapObserver<Entry = u8>,
@@ -2183,6 +2230,15 @@ where
21832230
}
21842231
}
21852232

2233+
impl<'a, T, const DIFFERENTIAL: bool> AsRef<Self> for MultiMapObserver<'a, T, DIFFERENTIAL>
2234+
where
2235+
T: 'static + Default + Copy + Serialize + Debug,
2236+
{
2237+
fn as_ref(&self) -> &Self {
2238+
self
2239+
}
2240+
}
2241+
21862242
impl<'a, T, const DIFFERENTIAL: bool> MapObserver for MultiMapObserver<'a, T, DIFFERENTIAL>
21872243
where
21882244
T: 'static
@@ -2539,6 +2595,15 @@ where
25392595
}
25402596
}
25412597

2598+
impl<T> AsRef<Self> for OwnedMapObserver<T>
2599+
where
2600+
T: 'static + Default + Copy + Serialize,
2601+
{
2602+
fn as_ref(&self) -> &Self {
2603+
self
2604+
}
2605+
}
2606+
25422607
impl<T> MapObserver for OwnedMapObserver<T>
25432608
where
25442609
T: 'static

0 commit comments

Comments
 (0)