pub struct Set { /* private fields */ }
Expand description
A struct representing a set of codes.
Implementations§
Source§impl Set
impl Set
Sourcepub fn new_from_code(code: Code) -> Self
pub fn new_from_code(code: Code) -> Self
Create a new code set, containing only the provided code. This is a free operation.
Sourcepub fn intersected_with(self, code_set: Set) -> Set
pub fn intersected_with(self, code_set: Set) -> Set
Get a new code set, that contains only the elements contained in both this set, as well as the provided set.
Sourcepub fn union_with(self, code_set: Set) -> Set
pub fn union_with(self, code_set: Set) -> Set
Get a new code set that contains all elements contained in either this set, or the provided set.
Sourcepub fn empty() -> Set
pub fn empty() -> Set
Return an empty set.
§Example
use turing_machine_ai::code::Set;
let empty_set = Set::empty();
assert_eq!(empty_set.size(), 0);
Sourcepub fn all() -> Set
pub fn all() -> Set
Return a set containing all codes.
§Example
use turing_machine_ai::code::Set;
let complete_set = Set::all();
assert_eq!(complete_set.size(), 125);
Sourcepub fn size(self) -> u32
pub fn size(self) -> u32
Get the size of this code set.
§Example
use turing_machine_ai::code::Set;
assert_eq!(Set::all().size(), 125);
assert_eq!(Set::empty().size(), 0);
Sourcepub fn from_closure(checker: fn(Code) -> bool) -> Self
pub fn from_closure(checker: fn(Code) -> bool) -> Self
Construct a new code set based on a closure that returns true
for any
code that must be in the set.
Sourcepub fn contains(self, code: Code) -> bool
pub fn contains(self, code: Code) -> bool
Returns whether the given code is part of this set.
use turing_machine_ai::code::{Set, Code};
let code_1 = Code::from_digits(1, 2, 3)?;
let code_2 = Code::from_digits(3, 3, 5)?;
let set = Set::new_from_code(code_1);
assert!(set.contains(code_1));
assert!(!set.contains(code_2));
Trait Implementations§
Source§impl FromIterator<Code> for Set
impl FromIterator<Code> for Set
Source§fn from_iter<T: IntoIterator<Item = Code>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Code>>(iter: T) -> Self
Create a new code set containing all codes in the iterator.
Source§impl FromIterator<Set> for Set
impl FromIterator<Set> for Set
impl Copy for Set
impl Eq for Set
impl StructuralPartialEq for Set
Auto Trait Implementations§
impl Freeze for Set
impl RefUnwindSafe for Set
impl Send for Set
impl Sync for Set
impl Unpin for Set
impl UnwindSafe for Set
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more