Document State methods

This commit is contained in:
Brandon Dyck 2024-09-30 15:42:26 -06:00
parent 526e40323d
commit 6e572d2748

View File

@ -142,6 +142,13 @@ type State[In any] struct {
pos uint64
}
// Read fills dst with data from this State's position in the underlying source.
// It returns the number of data it read and a new State for the position at which
// the read ended, and an error if the read either (1) failed or (2) reached the
// end of the source before filling dst. All reads from a given State will return
// data from the same position the source.
// If the source had too few data left to fill dst, or if the State's position is
// at or past the end of the source, err will be io.EOF.
func (s State[In]) Read(dst []In) (n uint64, next State[In], err error) {
if s.pos > math.MaxInt64 {
return 0, s, io.EOF
@ -159,10 +166,12 @@ func (s State[In]) Read(dst []In) (n uint64, next State[In], err error) {
return uint64(nread), s, err
}
// Pos returns this State's position.
func (s State[In]) Pos() uint64 {
return s.pos
}
// At returns a State pointing at pos in the same data source.
func (s State[In]) At(pos uint64) State[In] {
return State[In]{r: s.r, pos: pos}
}