Cursor

public struct Cursor { /* private fields */ }

Readable over an in-memory Array[UInt8] with a movable position.

Mirrors the role of Rust's io::Cursor — useful for tests, parsers, and any place a byte buffer needs to be presented as a Readable stream. The position is clamped to [0, count] by setPosition. Cursor clones share the underlying COW array.

Examples

var c = Cursor(data: [10, 20, 30].asArray()); var buf = Array[UInt8](repeating: 0, count: 2); try c.read(into: buf.asSlice()); // .Ok(2); buf == [10, 20] c.position() // 2

Properties

var data: Array[UInt8]
public var position: Int64

Initializers

public init(data: Array[UInt8])

Builds a cursor positioned at byte 0 over data.

Methods

public mutating func setPosition(to: Int64)

Sets the position. Negative values clamp to 0; values past the end clamp to count.

ImplementsReadable

Methods

public mutating func read(into: ArraySlice[UInt8]) -> Result[Int64, IoError]

Reads from the current position; returns .Ok(0) at EOF and advances the position by the byte count returned.

ImplementsCloneable

Methods

public func clone() -> Cursor

Deep-clones the underlying byte array and copies the position.

Defined in lang/std/io/read.ks