diff --git a/pkg/specter/unitloading.go b/pkg/specter/unitloading.go index 6773701..50826f1 100644 --- a/pkg/specter/unitloading.go +++ b/pkg/specter/unitloading.go @@ -50,15 +50,15 @@ type Unit interface { // // wrapped := Spectre.UnitOf(myValue) // unwrapped := wrapped.Unwrap() -type WrappingUnit[T any] struct { +type WrappingUnit struct { id UnitID kind UnitKind source Source - wrapped T + wrapped any } -func UnitOf[T any](v T, id UnitID, kind UnitKind, source Source) *WrappingUnit[T] { - return &WrappingUnit[T]{ +func UnitOf(v any, id UnitID, kind UnitKind, source Source) *WrappingUnit { + return &WrappingUnit{ id: id, kind: kind, source: source, @@ -67,28 +67,30 @@ func UnitOf[T any](v T, id UnitID, kind UnitKind, source Source) *WrappingUnit[T } func UnwrapUnit[T any](unit Unit) (value T, ok bool) { - w, ok := unit.(*WrappingUnit[T]) + w, ok := unit.(*WrappingUnit) if !ok { return value, false } - return w.wrapped, true + v, ok := w.wrapped.(T) + + return v, ok } -func (w *WrappingUnit[T]) ID() UnitID { +func (w *WrappingUnit) ID() UnitID { return w.id } -func (w *WrappingUnit[T]) Kind() UnitKind { +func (w *WrappingUnit) Kind() UnitKind { return w.kind } -func (w *WrappingUnit[T]) Source() Source { +func (w *WrappingUnit) Source() Source { return w.source } // Unwrap returns the wrapped value. -func (w *WrappingUnit[T]) Unwrap() T { +func (w *WrappingUnit) Unwrap() any { return w.wrapped } diff --git a/pkg/specter/unitloading_test.go b/pkg/specter/unitloading_test.go index d07ec98..dfd8d44 100644 --- a/pkg/specter/unitloading_test.go +++ b/pkg/specter/unitloading_test.go @@ -412,20 +412,20 @@ func TestUnitLoaderAdapter(t *testing.T) { } func TestUnwrapUnit(t *testing.T) { - type then[T any] struct { - value T + type then struct { + value any ok bool } - type testCase[T any] struct { + type testCase struct { name string when specter.Unit - then then[T] + then then } - tests := []testCase[string]{ + tests := []testCase{ { name: "Unwrap of non wrapped unit should return zero value and false", when: testutils.NewUnitStub("id", "kind", specter.Source{}), - then: then[string]{ + then: then{ value: "", ok: false, }, @@ -433,7 +433,7 @@ func TestUnwrapUnit(t *testing.T) { { name: "Unwrap of a wrapped unit should return the value and true", when: specter.UnitOf("hello", "id", "kind", specter.Source{}), - then: then[string]{ + then: then{ value: "hello", ok: true, }, diff --git a/pkg/testutils/unitproc.go b/pkg/testutils/unitproc.go index 292d3b7..10ce73b 100644 --- a/pkg/testutils/unitproc.go +++ b/pkg/testutils/unitproc.go @@ -19,5 +19,5 @@ import ( ) func NewUnitStub(id specter.UnitID, kind specter.UnitKind, source specter.Source) specter.Unit { - return specter.UnitOf[any](nil, id, kind, source) + return specter.UnitOf(nil, id, kind, source) }