Documentation

Overview

    Package vars contains basic types for manipulating Elvish variables.

    Index

    Constants

    This section is empty.

    Variables

    View Source
    var (
    	ErrPathMustBeString           = errors.New("path must be string")
    	ErrPathCannotContainColonZero = errors.New(`path cannot contain colon or \0`)
    )

      Errors

      View Source
      var ErrSetReadOnlyVar = errors.New("read-only variable; cannot be set")

        ErrSetReadOnlyVar is returned by the Set method of a read-only variable.

        Functions

        func DelElement

        func DelElement(variable Var, indices []interface{}) error

          DelElement deletes an element. It uses a similar process to MakeElement, except that the last level of container needs to be Dissoc-able instead of Assoc-able.

          func ElementErrorLevel

          func ElementErrorLevel(err error) int

            ElementErrorLevel returns the level of an error returned by MakeElement or DelElement. Level 0 represents that the error is about the variable itself. If the argument was not returned from MakeVariable, -1 is returned.

            func IsBlackhole

            func IsBlackhole(v Var) bool

              IsBlackhole returns whether the variable is a blackhole variable.

              Types

              type PtrVar

              type PtrVar struct {
              	// contains filtered or unexported fields
              }

              func FromPtr

              func FromPtr(p interface{}) PtrVar

                FromPtr creates a variable from a pointer. The variable is kept in sync with the value the pointer points to, converting with vals.ScanToGo and vals.FromGo when Get and Set. Its access is guarded by a new mutex.

                func FromPtrWithMutex

                func FromPtrWithMutex(p interface{}, m *sync.RWMutex) PtrVar

                  FromPtrWithMutex creates a variable from a pointer. The variable is kept in sync with the value the pointer points to, converting with vals.ScanToGo and vals.FromGo when Get and Set. Its access is guarded by the supplied mutex.

                  func (PtrVar) Get

                  func (v PtrVar) Get() interface{}

                    Get returns the value pointed by the pointer, after conversion using FromGo.

                    func (PtrVar) GetRaw

                    func (v PtrVar) GetRaw() interface{}

                      GetRaw returns the value pointed by the pointer without any conversion.

                      func (PtrVar) Set

                      func (v PtrVar) Set(val interface{}) error

                        Set sets the value pointed by the pointer, after conversion using ScanToGo.

                        type Var

                        type Var interface {
                        	Set(v interface{}) error
                        	Get() interface{}
                        }

                          Var represents an Elvish variable.

                          func FromEnv

                          func FromEnv(name string) Var

                            FromEnv returns a Var corresponding to the named environment variable.

                            func FromGet

                            func FromGet(get func() interface{}) Var

                              FromGet makes a variable from a get callback. The variable is read-only.

                              func FromInit

                              func FromInit(v interface{}) Var

                                FromInit creates a variable with an initial value. The variable created can be assigned values of any type.

                                func FromSetGet

                                func FromSetGet(set func(interface{}) error, get func() interface{}) Var

                                  FromSetGet makes a variable from a set callback and a get callback.

                                  func HeadOfElement

                                  func HeadOfElement(v Var) Var

                                    HeadOfElement gets the underlying head variable of an element variable, or nil if the argument is not an element variable.

                                    func MakeElement

                                    func MakeElement(v Var, indices []interface{}) (Var, error)

                                      MakeElement returns a variable, that when set, simulates the mutation of an element.

                                      func NewBlackhole

                                      func NewBlackhole() Var

                                        NewBlackhole returns a blackhole variable. Assignments to a blackhole variable will be discarded, and getting a blackhole variable always returns nil.

                                        func NewEnvListVar

                                        func NewEnvListVar(name string) Var

                                          NewEnvListVar returns a variable whose value is a list synchronized with an environment variable with the elements joined by os.PathListSeparator.

                                          Elements in the value of the variable must be strings, and cannot contain os.PathListSeparator or \0; attempting to put any in its elements will result in an error.

                                          func NewReadOnly

                                          func NewReadOnly(v interface{}) Var

                                            NewReadOnly creates a variable that is read-only and always returns an error on Set.