Add copy method to VarSet

This commit is contained in:
Jeffrey Regan
2019-06-07 13:01:34 -07:00
parent c9300edead
commit d9b0c4c84c
3 changed files with 14 additions and 9 deletions

View File

@@ -75,15 +75,20 @@ type VarSet struct {
set []Var
}
// Set returns a copy of the var set.
func (vs *VarSet) Set() []Var {
// AsSlice returns the vars as a slice.
func (vs *VarSet) AsSlice() []Var {
s := make([]Var, len(vs.set))
copy(s, vs.set)
return s
}
// Copy returns a copy of the var set.
func (vs *VarSet) Copy() VarSet {
return VarSet{set: vs.AsSlice()}
}
// MergeSet absorbs other vars with error on name collision.
func (vs *VarSet) MergeSet(incoming *VarSet) error {
func (vs *VarSet) MergeSet(incoming VarSet) error {
return vs.MergeSlice(incoming.set)
}