github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/vals/pipe.go (about) 1 package vals 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/u-root/u-root/cmds/core/elvish/hash" 8 ) 9 10 // Pipe wraps a pair of pointers to os.File that are the two ends of the same 11 // pipe. 12 type Pipe struct { 13 ReadEnd, WriteEnd *os.File 14 } 15 16 var _ interface{} = Pipe{} 17 18 // NewPipe creates a new Pipe value. 19 func NewPipe(r, w *os.File) Pipe { 20 return Pipe{r, w} 21 } 22 23 func (Pipe) Kind() string { 24 return "pipe" 25 } 26 27 func (p Pipe) Equal(rhs interface{}) bool { 28 return p == rhs 29 } 30 31 func (p Pipe) Hash() uint32 { 32 h := hash.DJBInit 33 h = hash.DJBCombine(h, hash.Hash(p.ReadEnd.Fd())) 34 h = hash.DJBCombine(h, hash.Hash(p.WriteEnd.Fd())) 35 return h 36 } 37 38 func (p Pipe) Repr(int) string { 39 return fmt.Sprintf("<pipe{%v %v}>", p.ReadEnd.Fd(), p.WriteEnd.Fd()) 40 }