github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/diag/range.go (about) 1 package diag 2 3 // Ranger wraps the Range method. 4 type Ranger interface { 5 // Range returns the range associated with the value. 6 Range() Ranging 7 } 8 9 // Ranging represents a range [From, To) within an indexable sequence. Structs 10 // can embed Ranging to satisfy the Ranger interface. 11 type Ranging struct { 12 From int 13 To int 14 } 15 16 // Range returns the Ranging itself. 17 func (r Ranging) Range() Ranging { return r } 18 19 // PointRanging returns a zero-width Ranging at the given point. 20 func PointRanging(p int) Ranging { 21 return Ranging{p, p} 22 } 23 24 // MixedRanging returns a Ranging from the start position of a to the end 25 // position of b. 26 func MixedRanging(a, b Ranger) Ranging { 27 return Ranging{a.Range().From, b.Range().To} 28 }