@@ -85,6 +85,9 @@ pub const fn cardinality<T: Sequence>() -> usize {
8585
8686/// Returns an iterator over all values of type `T`.
8787///
88+ /// Values are yielded in the order defined by [`Sequence::next`], starting with
89+ /// [`Sequence::first`].
90+ ///
8891/// # Example
8992/// ```
9093/// use enum_iterator::{all, Sequence};
@@ -121,6 +124,8 @@ pub fn reverse_all<T: Sequence>() -> ReverseAll<T> {
121124
122125/// Returns the next value of type `T` or `None` if this was the end.
123126///
127+ /// Same as [`Sequence::next`].
128+ ///
124129/// # Example
125130/// ```
126131/// use enum_iterator::{next, Sequence};
@@ -134,7 +139,7 @@ pub fn next<T: Sequence>(x: &T) -> Option<T> {
134139 x. next ( )
135140}
136141
137- /// Returns the next value of type `T` or `T:: first()` if this was the end.
142+ /// Returns the next value of type `T` or [` first()`](first) if this was the end.
138143///
139144/// # Example
140145/// ```
@@ -151,6 +156,8 @@ pub fn next_cycle<T: Sequence>(x: &T) -> Option<T> {
151156
152157/// Returns the previous value of type `T` or `None` if this was the beginning.
153158///
159+ /// Same as [`Sequence::previous`].
160+ ///
154161/// # Example
155162/// ```
156163/// use enum_iterator::{previous, Sequence};
@@ -164,7 +171,7 @@ pub fn previous<T: Sequence>(x: &T) -> Option<T> {
164171 x. previous ( )
165172}
166173
167- /// Returns the previous value of type `T` or `T:: last()` if this was the beginning.
174+ /// Returns the previous value of type `T` or [` last()`](last) if this was the beginning.
168175///
169176/// # Example
170177/// ```
@@ -181,6 +188,8 @@ pub fn previous_cycle<T: Sequence>(x: &T) -> Option<T> {
181188
182189/// Returns the first value of type `T`.
183190///
191+ /// Same as [`Sequence::first`].
192+ ///
184193/// # Example
185194/// ```
186195/// use enum_iterator::{first, Sequence};
@@ -196,6 +205,8 @@ pub fn first<T: Sequence>() -> Option<T> {
196205
197206/// Returns the last value of type `T`.
198207///
208+ /// Same as [`Sequence::last`].
209+ ///
199210/// # Example
200211/// ```
201212/// use enum_iterator::{last, Sequence};
@@ -264,6 +275,14 @@ impl<T: Sequence> FusedIterator for ReverseAll<T> {}
264275///
265276/// The cardinality (number of values) of the type must not exceed `usize::MAX`.
266277///
278+ /// # Laws
279+ ///
280+ /// `T: Sequence` implies the following assertions:
281+ /// - `T::first().and_then(|x| x.previous()).is_none()`
282+ /// - `T::last().and_then(|x| x.next()).is_none()`
283+ /// - `T::first().is_none()` ⇔ `T::last().is_none()`
284+ /// - `std::iter::successors(T::first(), T::next)` must eventually yield `T::last()`.
285+ ///
267286/// # Examples
268287/// ## C-like enumeration
269288///
@@ -364,6 +383,19 @@ pub trait Sequence: Sized {
364383
365384 /// Returns value following `*self` or `None` if this was the end.
366385 ///
386+ /// Values are yielded in the following order. Comparisons between values are based on their
387+ /// relative order as yielded by `next`; an element yielded after another is considered greater.
388+ ///
389+ /// - For primitive types, in increasing order (same as `Ord`).
390+ /// - For arrays and tuples, in lexicographic order of the sequence of their elements.
391+ /// - When derived for an enumeration, in variant definition order.
392+ /// - When derived for a structure, in lexicographic order of the sequence of its fields taken
393+ /// in definition order.
394+ ///
395+ /// The order described above is the same as `Ord` if any custom `Sequence` implementation
396+ /// follows `Ord` and any enumeration has its variants defined in increasing order of
397+ /// discriminant.
398+ ///
367399 /// # Example
368400 /// ```
369401 /// use enum_iterator::Sequence;
0 commit comments