This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
generated from FrangipaneTeam/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset_value.go
186 lines (146 loc) · 5.12 KB
/
set_value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// -------------------------------------------------------------------- //
// ! DO NOT EDIT. This file is auto-generated from template ! //
// -------------------------------------------------------------------- //
package supertypes
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)
// Ensure the implementation satisfies the expected interfaces.
var _ basetypes.SetValuable = SetValue{}
var _ basetypes.SetValuable = SetValueOf[struct{}]{}
// * SetType
type SetValue struct {
basetypes.SetValue
}
func (v SetValue) Equal(o attr.Value) bool {
other, ok := o.(SetValue)
if !ok {
return false
}
return v.SetValue.Equal(other.SetValue)
}
func (v SetValue) Type(ctx context.Context) attr.Type {
return SetType{
SetType: v.SetValue.Type(ctx).(basetypes.SetType),
}
}
func (v SetValue) ToSetValue(_ context.Context) (basetypes.SetValue, diag.Diagnostics) {
return v.SetValue, nil
}
func NewSetNull(elementType attr.Type) SetValue {
return SetValue{
SetValue: basetypes.NewSetNull(elementType),
}
}
func NewSetUnknown(elementType attr.Type) SetValue {
return SetValue{
SetValue: basetypes.NewSetUnknown(elementType),
}
}
func NewSetValueMust(elementType attr.Type, elements []attr.Value) SetValue {
return SetValue{
SetValue: basetypes.NewSetValueMust(elementType, elements),
}
}
func NewSetValue(elementType attr.Type, elements []attr.Value) (SetValue, diag.Diagnostics) {
x, d := basetypes.NewSetValue(elementType, elements)
return SetValue{
SetValue: x,
}, d
}
func NewSetValueFrom(ctx context.Context, elementType attr.Type, elements any) (SetValue, diag.Diagnostics) {
x, d := basetypes.NewSetValueFrom(ctx, elementType, elements)
return SetValue{
SetValue: x,
}, d
}
// * CustomFunc
func (v *SetValue) Get(ctx context.Context, target interface{}, allowUnhandled bool) (diag diag.Diagnostics) {
return v.SetValue.ElementsAs(ctx, target, allowUnhandled)
}
func (v *SetValue) Set(ctx context.Context, elements any) diag.Diagnostics {
var d diag.Diagnostics
v.SetValue, d = types.SetValueFrom(ctx, v.ElementType(ctx), elements)
return d
}
func (v *SetValue) SetNull(ctx context.Context) {
v.SetValue = basetypes.NewSetNull(v.ElementType(ctx))
}
func (v *SetValue) SetUnknown(ctx context.Context) {
v.SetValue = basetypes.NewSetUnknown(v.ElementType(ctx))
}
func (v SetValue) IsKnown() bool {
return !v.SetValue.IsNull() && !v.SetValue.IsUnknown()
}
// * SetTypeOf
type SetValueOf[T any] struct {
basetypes.SetValue
}
// ToSetValue converts the given value to a SetValue.
func (v SetValueOf[T]) ToSetValue(_ context.Context) (basetypes.SetValue, diag.Diagnostics) {
return v.SetValue, nil
}
// Equal returns true if the given value is equal to this value.
func (v SetValueOf[T]) Equal(o attr.Value) bool {
other, ok := o.(SetValueOf[T])
if !ok {
return false
}
return v.SetValue.Equal(other.SetValue)
}
// Type returns the type of this value.
func (v SetValueOf[T]) Type(ctx context.Context) attr.Type {
return NewSetTypeOf[T](ctx)
}
// Get returns a SetValueOf from the given value.
func (v SetValueOf[T]) Get(ctx context.Context) (values []T, diags diag.Diagnostics) {
values = make([]T, len(v.SetValue.Elements()))
diags.Append(v.SetValue.ElementsAs(ctx, &values, false)...)
return
}
// Set sets the value of this value.
func (v *SetValueOf[T]) Set(ctx context.Context, elements []T) diag.Diagnostics {
var d diag.Diagnostics
v.SetValue, d = types.SetValueFrom(ctx, v.ElementType(ctx), elements)
return d
}
// NewSetValueOfUnknown returns a new SetValueOf with an unknown value.
func NewSetValueOfUnknown[T any](ctx context.Context) SetValueOf[T] {
return SetValueOf[T]{
SetValue: basetypes.NewSetUnknown(ElementTypeMust[T](ctx)),
}
}
// NewSetValueOfNull returns a new SetValueOf with a null value.
func NewSetValueOfNull[T any](ctx context.Context) SetValueOf[T] {
return SetValueOf[T]{
SetValue: basetypes.NewSetNull(ElementTypeMust[T](ctx)),
}
}
// newSetValueOf is a helper function to create a new SetValueOf.
func newSetValueOf[T any](ctx context.Context, elements any) SetValueOf[T] {
return SetValueOf[T]{SetValue: MustDiag(basetypes.NewSetValueFrom(ctx, ElementTypeMust[T](ctx), elements))}
}
// NewSetValueOfSlice returns a new SetValueOf with the given slice value.
func NewSetValueOfSlice[T any](ctx context.Context, elements []T) SetValueOf[T] {
return newSetValueOf[T](ctx, elements)
}
// NewSetValueOfSlicePtr returns a new SetValueOf with the given slice value.
func NewSetValueOfSlicePtr[T any](ctx context.Context, elements []*T) SetValueOf[T] {
return newSetValueOf[T](ctx, elements)
}
// IsKnown returns true if the value is known.
func (v SetValueOf[T]) IsKnown() bool {
return !v.SetValue.IsNull() && !v.SetValue.IsUnknown()
}
// SetNull sets the value to null.
func (v *SetValueOf[T]) SetNull(ctx context.Context) {
(*v) = NewSetValueOfNull[T](ctx)
}
// SetUnknown sets the value to unknown.
func (v *SetValueOf[T]) SetUnknown(ctx context.Context) {
(*v) = NewSetValueOfUnknown[T](ctx)
}