Trait Collection

Source
pub trait Collection<Item>: IntoIterator<Item = Item> + Indexable<Item> { }
Expand description

A generic iterable, indexable sequence supporting deterministic traversal.

This trait captures the minimal capabilities required for iteration and positional access without assuming construction or mutation.

§Capabilities:

  • IntoIterator: Enables deterministic iteration over contained values.
  • Indexable: Provides direct indexed and range-based access to elements.

§Design Notes:

  • Represents read-only traversal + positional access semantics.
  • Does not assume the ability to construct or mutate the sequence.
  • Compatible with both fixed-size and dynamic containers.
  • Enables algorithms that require both iteration and indexing.

§Supported Types:

  • Fixed-size arrays (e.g. [T; N])
  • Dynamic collections (e.g. Vec<T>, VecDeque, BoundedVec)

§Usage:

Use this trait when:

  • iteration and indexed access are required,
  • no assumptions about construction or mutation should be made.

For construction and mutation, see Growable.

Implementors§

Source§

impl<T, Item> Collection<Item> for T
where T: IntoIterator<Item = Item> + Indexable<Item>,