mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 07:11:30 +11:00
Fix clippy issues
This commit is contained in:
parent
f7a35f356e
commit
dafc9a375a
|
@ -76,6 +76,11 @@ impl<C: Config> Chunks<C> {
|
|||
self.chunks.len()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are no loaded chunks.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.chunks.len() == 0
|
||||
}
|
||||
|
||||
/// Gets a shared reference to the chunk at the provided position.
|
||||
///
|
||||
/// If there is no chunk at the position, then `None` is returned.
|
||||
|
|
|
@ -90,6 +90,12 @@ impl<C: Config> Clients<C> {
|
|||
self.slab.len()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are no clients on the server. This includes
|
||||
/// clients for which [`Client::is_disconnected`] returns true.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.slab.len() == 0
|
||||
}
|
||||
|
||||
/// Returns a shared reference to the client with the given ID. If
|
||||
/// the ID is invalid, then `None` is returned.
|
||||
pub fn get(&self, client: ClientId) -> Option<&Client<C>> {
|
||||
|
|
|
@ -146,6 +146,11 @@ impl<C: Config> Entities<C> {
|
|||
self.slab.len()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are no entities.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.slab.len() == 0
|
||||
}
|
||||
|
||||
/// Gets the [`EntityId`] of the entity with the given UUID in an efficient
|
||||
/// manner.
|
||||
///
|
||||
|
|
|
@ -40,7 +40,11 @@ impl<C: Config> PlayerLists<C> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Creates a new player list and returns an exclusive reference to it along
|
||||
/// with its ID.
|
||||
///
|
||||
/// The player list is automatically removed at the end of the tick once all
|
||||
/// IDs to it have been dropped.
|
||||
pub fn insert(&mut self, state: C::PlayerListState) -> (PlayerListId, &mut PlayerList<C>) {
|
||||
let (key, pl) = self.slab.insert(PlayerList {
|
||||
state,
|
||||
|
@ -54,14 +58,28 @@ impl<C: Config> PlayerLists<C> {
|
|||
(PlayerListId(key), pl)
|
||||
}
|
||||
|
||||
/// Returns the number of player lists.
|
||||
pub fn len(&self) -> usize {
|
||||
self.slab.len()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are no player lists.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.slab.len() == 0
|
||||
}
|
||||
|
||||
/// Gets a shared reference to the player list with the given player list
|
||||
/// ID.
|
||||
///
|
||||
/// This operation is infallible because [`PlayerListId`] is refcounted.
|
||||
pub fn get(&self, id: &PlayerListId) -> &PlayerList<C> {
|
||||
self.slab.get(&id.0)
|
||||
}
|
||||
|
||||
/// Gets an exclusive reference to the player list with the given player
|
||||
/// list ID.
|
||||
///
|
||||
/// This operation is infallible because [`PlayerListId`] is refcounted.
|
||||
pub fn get_mut(&mut self, id: &PlayerListId) -> &mut PlayerList<C> {
|
||||
self.slab.get_mut(&id.0)
|
||||
}
|
||||
|
|
|
@ -297,7 +297,7 @@ impl<T> FusedIterator for IterMut<'_, T> {}
|
|||
|
||||
impl<T> Clone for ParIter<'_, T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self { slab: &self.slab }
|
||||
Self { slab: self.slab }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ impl<T: Clone> Clone for Slot<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, Ord, Debug)]
|
||||
#[derive(Clone, Eq, Debug)]
|
||||
pub struct Key(Arc<usize>);
|
||||
|
||||
impl PartialEq for Key {
|
||||
|
@ -44,6 +44,12 @@ impl PartialOrd for Key {
|
|||
}
|
||||
}
|
||||
|
||||
impl Ord for Key {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Key {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
Arc::as_ptr(&self.0).hash(state)
|
||||
|
|
|
@ -68,12 +68,12 @@ impl<T> VersionedSlab<T> {
|
|||
|
||||
pub fn get(&self, key: Key) -> Option<&T> {
|
||||
let slot = self.slab.get(key.index as usize)?;
|
||||
(slot.version == key.version).then(|| &slot.value)
|
||||
(slot.version == key.version).then_some(&slot.value)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, key: Key) -> Option<&mut T> {
|
||||
let slot = self.slab.get_mut(key.index as usize)?;
|
||||
(slot.version == key.version).then(|| &mut slot.value)
|
||||
(slot.version == key.version).then_some(&mut slot.value)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
|
|
|
@ -79,6 +79,11 @@ impl<C: Config> Worlds<C> {
|
|||
self.slab.len()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are no worlds on the server.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.slab.len() == 0
|
||||
}
|
||||
|
||||
/// Returns a shared reference to the world with the given ID. If
|
||||
/// the ID is invalid, then `None` is returned.
|
||||
pub fn get(&self, world: WorldId) -> Option<&World<C>> {
|
||||
|
|
Loading…
Reference in a new issue