github.com/elves/elvish@v0.15.0/pkg/eval/vars/read_only.go (about) 1 package vars 2 3 import ( 4 "errors" 5 ) 6 7 // ErrSetReadOnlyVar is returned by the Set method of a read-only variable. 8 var ErrSetReadOnlyVar = errors.New("read-only variable; cannot be set") 9 10 type readOnly struct { 11 value interface{} 12 } 13 14 // NewReadOnly creates a variable that is read-only and always returns an error 15 // on Set. 16 func NewReadOnly(v interface{}) Var { 17 return readOnly{v} 18 } 19 20 func (rv readOnly) Set(val interface{}) error { 21 return ErrSetReadOnlyVar 22 } 23 24 func (rv readOnly) Get() interface{} { 25 return rv.value 26 }