Skip to content

Commit 79f9e06

Browse files
authored
Tiny improvements for cranelift_entity::EntitySet (bytecodealliance#10469)
* Document return value of `EntitySet::insert` * Implement a better `Debug` implementation for `EntitySet`
1 parent efb4e4c commit 79f9e06

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cranelift/entity/src/set.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
33
use crate::keys::Keys;
44
use crate::EntityRef;
5+
use core::fmt;
56
use core::marker::PhantomData;
67
use cranelift_bitset::CompoundBitSet;
78

89
/// A set of `K` for densely indexed entity references.
910
///
1011
/// The `EntitySet` data structure uses the dense index space to implement a set with a bitvector.
1112
/// Like `SecondaryMap`, an `EntitySet` is used to associate secondary information with entities.
12-
#[derive(Debug, Clone, PartialEq, Eq)]
13+
#[derive(Clone, PartialEq, Eq)]
1314
#[cfg_attr(
1415
feature = "enable-serde",
1516
derive(serde_derive::Serialize, serde_derive::Deserialize)
@@ -22,6 +23,15 @@ where
2223
unused: PhantomData<K>,
2324
}
2425

26+
impl<K: fmt::Debug> fmt::Debug for EntitySet<K>
27+
where
28+
K: EntityRef,
29+
{
30+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31+
f.debug_set().entries(self.keys()).finish()
32+
}
33+
}
34+
2535
impl<K: EntityRef> Default for EntitySet<K> {
2636
fn default() -> Self {
2737
Self {
@@ -85,6 +95,9 @@ where
8595
}
8696

8797
/// Insert the element at `k`.
98+
///
99+
/// Returns `true` if `k` was not present in the set, i.e. this is a
100+
/// newly-added element. Returns `false` otherwise.
88101
pub fn insert(&mut self, k: K) -> bool {
89102
let index = k.index();
90103
self.bitset.insert(index)

0 commit comments

Comments
 (0)