Skip to content

std.derives.* (reference)

This page documents the derive-related trait families available under std.derives.*. Import these traits when you want to adopt them explicitly or refer to them in annotations and bounds.

Related pages

Importing derive traits

Import from the specific derive submodule:

from std.derives.comparison import Eq, Ord, Hash
from std.derives.copying import Clone, Copy, Default
from std.derives.string import Debug, Display
from std.derives.collection import Contains, Bool, Len, Iterable, Iterator, FallibleIterator

Surface model

Traits under std.derives.* describe capabilities such as equality, ordering, copying, and display formatting.

  • Many of these traits are also the ones used by @derive(...).
  • You can import the trait names directly when you want to refer to them in type-level positions.
  • The collection traits in std.derives.collection are ordinary trait families for collection-like behavior, not derive markers.

Submodules

std.derives.comparison

Provides:

  • Eq
  • Ord
  • Hash

See Comparison.

std.derives.copying

Provides:

  • Clone
  • Copy
  • Default

See Copying and Default.

std.derives.string

Provides:

  • Debug
  • Display

See String representation.

std.derives.collection

Provides collection-protocol traits for custom types, including:

  • Contains[T]
  • Bool
  • Len
  • Iterable[T]
  • Iterator[T]
  • FallibleIterator[T, E]

Use these when you want a custom type to participate in collection-style APIs through explicit trait adoption. FallibleIterator[T, E] is the single-pass protocol for sources whose next poll can return an item, ordinary exhaustion, or a typed error; consume it with for item in stream?: or its fallible terminals. Bool is available, but prefer explicit checks for Option, Result, emptiness, and named boolean state when that is the behavior you mean.