bevy_reflect

Trait Set

Source
pub trait Set: PartialReflect {
    // Required methods
    fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect>;
    fn len(&self) -> usize;
    fn iter(&self) -> Box<dyn Iterator<Item = &dyn PartialReflect> + '_>;
    fn drain(&mut self) -> Vec<Box<dyn PartialReflect>>;
    fn clone_dynamic(&self) -> DynamicSet;
    fn insert_boxed(&mut self, value: Box<dyn PartialReflect>) -> bool;
    fn remove(&mut self, value: &dyn PartialReflect) -> bool;
    fn contains(&self, value: &dyn PartialReflect) -> bool;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait used to power set-like operations via reflection.

Sets contain zero or more entries of a fixed type, and correspond to types like HashSet and BTreeSet. The order of these entries is not guaranteed by this trait.

§Hashing and equality

All values are expected to return a valid hash value from PartialReflect::reflect_hash and be comparable using PartialReflect::reflect_partial_eq. If using the #[derive(Reflect)] macro, this can be done by adding #[reflect(Hash, PartialEq)] to the entire struct or enum. The ordering is expected to be total, that is as if the reflected type implements the Eq trait. This is true even for manual implementors who do not hash or compare values, as it is still relied on by DynamicSet.

§Example

use bevy_reflect::{PartialReflect, Set};
use bevy_utils::HashSet;


let foo: &mut dyn Set = &mut HashSet::<u32>::new();
foo.insert_boxed(Box::new(123_u32));
assert_eq!(foo.len(), 1);

let field: &dyn PartialReflect = foo.get(&123_u32).unwrap();
assert_eq!(field.try_downcast_ref::<u32>(), Some(&123_u32));

Required Methods§

Source

fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect>

Returns a reference to the value.

If no value is contained, returns None.

Source

fn len(&self) -> usize

Returns the number of elements in the set.

Source

fn iter(&self) -> Box<dyn Iterator<Item = &dyn PartialReflect> + '_>

Returns an iterator over the values of the set.

Source

fn drain(&mut self) -> Vec<Box<dyn PartialReflect>>

Drain the values of this set to get a vector of owned values.

After calling this function, self will be empty.

Source

fn clone_dynamic(&self) -> DynamicSet

Clones the set, producing a DynamicSet.

Source

fn insert_boxed(&mut self, value: Box<dyn PartialReflect>) -> bool

Inserts a value into the set.

If the set did not have this value present, true is returned. If the set did have this value present, false is returned.

Source

fn remove(&mut self, value: &dyn PartialReflect) -> bool

Removes a value from the set.

If the set did not have this value present, true is returned. If the set did have this value present, false is returned.

Source

fn contains(&self, value: &dyn PartialReflect) -> bool

Checks if the given value is contained in the set

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the list contains no elements.

Implementations on Foreign Types§

Source§

impl<V, S> Set for HashSet<V, S>

Source§

fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect>

Source§

fn len(&self) -> usize

Source§

fn iter(&self) -> Box<dyn Iterator<Item = &dyn PartialReflect> + '_>

Source§

fn drain(&mut self) -> Vec<Box<dyn PartialReflect>>

Source§

fn clone_dynamic(&self) -> DynamicSet

Source§

fn insert_boxed(&mut self, value: Box<dyn PartialReflect>) -> bool

Source§

fn remove(&mut self, value: &dyn PartialReflect) -> bool

Source§

fn contains(&self, value: &dyn PartialReflect) -> bool

Source§

impl<V, S> Set for HashSet<V, S>

Source§

fn get(&self, value: &dyn PartialReflect) -> Option<&dyn PartialReflect>

Source§

fn len(&self) -> usize

Source§

fn iter(&self) -> Box<dyn Iterator<Item = &dyn PartialReflect> + '_>

Source§

fn drain(&mut self) -> Vec<Box<dyn PartialReflect>>

Source§

fn clone_dynamic(&self) -> DynamicSet

Source§

fn insert_boxed(&mut self, value: Box<dyn PartialReflect>) -> bool

Source§

fn remove(&mut self, value: &dyn PartialReflect) -> bool

Source§

fn contains(&self, value: &dyn PartialReflect) -> bool

Implementors§