Skip to content

Commit bcd981d

Browse files
committed
fix: reduce requirements for the safe.List type
We do not need to require more than we actually need, as it simplifies other parts of the code. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent c2ab79b commit bcd981d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pkg/safe/state.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,20 @@ func StateModifyWithResult[T resource.Resource](ctx context.Context, st state.St
226226
return typeAssertOrZero[T](got, err)
227227
}
228228

229+
// ListedResource is an interface that represents a resource in a list.
230+
//
231+
// It is a subset of resource.Resource that only exposes required methods.
232+
type ListedResource interface {
233+
Metadata() *resource.Metadata
234+
}
235+
229236
// List is a type safe wrapper around resource.List.
230-
type List[T resource.Resource] struct {
237+
type List[T ListedResource] struct {
231238
list resource.List
232239
}
233240

234241
// NewList creates a new List.
235-
func NewList[T resource.Resource](list resource.List) List[T] {
242+
func NewList[T ListedResource](list resource.List) List[T] {
236243
return List[T]{list}
237244
}
238245

@@ -354,15 +361,15 @@ func (l *List[T]) Pointers() iter.Seq[resource.Pointer] {
354361
}
355362

356363
// ListIterator is a generic iterator over resource.Resource slice.
357-
type ListIterator[T resource.Resource] struct {
364+
type ListIterator[T ListedResource] struct {
358365
list List[T]
359366
pos int
360367
}
361368

362369
// IteratorFromList returns a new iterator over the given list.
363370
//
364371
// Deprecated: use [List.All] instead.
365-
func IteratorFromList[T resource.Resource](list List[T]) ListIterator[T] {
372+
func IteratorFromList[T ListedResource](list List[T]) ListIterator[T] {
366373
return ListIterator[T]{pos: 0, list: list}
367374
}
368375

0 commit comments

Comments
 (0)