DequeConsumingIterator
Owns a transferred deque and yields its FIFO payloads by ownership. Construction transfers allocator/backing without allocation or element moves. Each Next pops the front in O(1) bookkeeping, immediately destroying its valid moved-from slot. Remaining items and backing clean up on cursor destruction. No borrowed payload alias escapes; serialize traversal and cursor movement.
Module std.collections
import std.collections;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
DequeConsumingIterator
pub final class DequeConsumingIterator<T, A>
where T: Movable where A: Allocator, Defaultable, MovableOwns a transferred deque and yields its FIFO payloads by ownership. Construction transfers allocator/backing without allocation or element moves. Each Next pops the front in O(1) bookkeeping, immediately destroying its valid moved-from slot. Remaining items and backing clean up on cursor destruction. No borrowed payload alias escapes; serialize traversal and cursor movement. T: Movable payload yielded in original sequence order. A: Movable Defaultable allocator satisfying Allocator.
Example
module example.deque_consuming;
from std.collections import Deque, CreateConsumingIterator;
fn Main() -> i32 {
var Values = Deque<i32>();
if Values.TryPushBack(22) is .Err { Error = _ } { return 1; }
if Values.TryPushFront(20) is .Err { Error = _ } { return 2; }
var Cursor = CreateConsumingIterator(move(Values));
if !Values.IsEmpty { return 3; }
if Cursor.Next().Unwrap() != 20 { return 4; }
var Moved = move(Cursor);
if Cursor.Next() is .Some { Value = _ } { return 5; }
if Moved.Next().Unwrap() != 22 { return 6; }
if Moved.Next() is .Some { Value = _ } { return 7; }
if Moved.Next() is .Some { Value = _ } { return 8; }
return 0;
}DequeConsumingIterator.init
pub init(Source: readonly Self&) = delete;Rejects duplicate traversal/backing ownership. Source: Existing cursor.
DequeConsumingIterator.init
pub init(Source: mut Self&&)Transfers remaining FIFO ownership without moving elements. Source: Cursor left empty.
DequeConsumingIterator.operator
pub fn operator =(Source: readonly Self&) -> void = delete;Rejects duplicate backing. Source: Existing cursor. Return: No runtime result; this assignment is deleted and cannot be invoked.
DequeConsumingIterator.operator
pub fn operator =(Source: mut Self&&) -> void = delete;Rejects implicit replacement of partially consumed ownership. Source: Existing cursor. Return: No runtime result; this assignment is deleted and cannot be invoked.
DequeConsumingIterator.Next
pub fn Next() -> T?Transfers/removes the FIFO front, or reports sticky exhaustion. Return: Owned item, or none when no remaining element exists.
CreateConsumingIterator
pub fn CreateConsumingIterator<T, A>(mut Source: Deque<T, A>) -> DequeConsumingIterator<T, A>
where T: Movable where A: Allocator, Defaultable, MovableCreates a concrete owning FIFO cursor without allocation or element moves. T: Movable payload inferred from Source. A: Movable Defaultable allocator inferred from Source. Source: Owned deque; explicitly move a named owner. Return: Noncopy cursor yielding owned T in source order. Warning: Transfers backing and invalidates ordinary source views.