-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment.go
33 lines (27 loc) · 887 Bytes
/
segment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package traveller
import "reflect"
// Represents a path segment for matching.
type MatcherSegment struct {
traveller *Traveller
index int
}
// Get the traveller instance.
func (s MatcherSegment) Traveller() *Traveller {
return s.traveller
}
// Get the current index of the path.
func (s MatcherSegment) Index() int {
return s.index
}
// Go to the next path segment with a new value.
//
// False is returned when traversal should not be continued.
func (s MatcherSegment) Next(rv reflect.Value, parentRv reflect.Value, key any) bool {
return s.Traveller().Match(s.Index()+1, rv, parentRv, key)
}
// Stay on the current path segment while inspecting a new value.
//
// False is returned when traversal should not be continued.
func (s MatcherSegment) Stay(rv reflect.Value, parentRv reflect.Value, key any) bool {
return s.Traveller().Match(s.Index(), rv, parentRv, key)
}