std::contains
Import with import std::contains.
Exports
Section titled “Exports”Interfaces
interface Contains
Section titled “interface Contains”interface Contains<T> fn contains(c: self, x: T) -> Bool end
A collection that reports whether it holds a value: contains(c, x).
The std collections implement it:
Set<T>: whetherxis a member, by hash lookup.Map<K, V>: whetherxis a key, by hash lookup. A value is not a key.Range<T>: whetherxlies between the ends, by two comparisons. An exclusive range leaves out its end, and an unbounded one checks only its start.List<T>andVector<T>: whether an element is==tox, by a linear scan.Bytes: whether a byte equalsx, by a linear scan.String, at three type arguments: whether aStringoccurs as a substring, aRegexmatches anywhere, or aCodepointoccurs. A call takes the impl its argument’s type chooses.
Iter.contains returns membership under the same name without
implementing the interface: it scans any iterable, a lazy pipeline
included.
List, Vector, Bytes, String and Iter membership is linear in the
collection’s size, and stops at the first match. For repeated lookups,
convert to a Set once.
Elements compare as == does: a struct with a hand-written Equatable is
compared by it, and Float equality is reflexive, so a NaN element is
found by NaN and 0.0 by -0.0.
assert Set.contains(Set[1, 2], 1)
assert Map.contains({"a" => 1}, "a")
assert List.contains([1, 2, 3], 2)
assert Range.contains(1..5, 3)
Contains.contains
Section titled “Contains.contains”fn contains(c: self, x: T) -> Bool
interface Contains