github.com/cilium/cilium@v1.16.2/pkg/policy/api/rules.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package api 5 6 import ( 7 "fmt" 8 "strings" 9 ) 10 11 // Rules is a collection of api.Rule. 12 // 13 // All rules must be evaluated in order to come to a conclusion. While 14 // it is sufficient to have a single fromEndpoints rule match, none of 15 // the fromRequires may be violated at the same time. 16 // +deepequal-gen:private-method=true 17 type Rules []*Rule 18 19 func (rs Rules) String() string { 20 strRules := make([]string, 0, len(rs)) 21 22 for _, r := range rs { 23 strRules = append(strRules, fmt.Sprintf("%+v", r)) 24 } 25 26 return "[" + strings.Join(strRules, ",\n") + "]" 27 } 28 29 // DeepEqual is a deepequal function, deeply comparing the 30 // receiver with other. the receiver must be non-nil. 31 func (rs *Rules) DeepEqual(other *Rules) bool { 32 switch { 33 case (rs == nil) != (other == nil): 34 return false 35 case (rs == nil) && (other == nil): 36 return true 37 } 38 return rs.deepEqual(other) 39 }