From 4bf8570971933c060251163cab366101bee8f384 Mon Sep 17 00:00:00 2001 From: John Chadwick Date: Mon, 16 Sep 2024 13:03:08 -0400 Subject: [PATCH] Use proto2 Enum helper instead of toPointer My bad. --- legacy/translate.go | 8 ++------ legacy/translate_test.go | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/legacy/translate.go b/legacy/translate.go index 61aa7b9..f194148 100644 --- a/legacy/translate.go +++ b/legacy/translate.go @@ -70,7 +70,7 @@ func translateRules(rules protoreflect.Message) *pv.FieldConstraints { if msgRules.Get(msgDesc.Fields().ByName("required")).Bool() { constraints.Required = proto.Bool(true) } else if msgRules.Get(msgDesc.Fields().ByName("skip")).Bool() { - constraints.Ignore = toPointer(pv.Ignore_IGNORE_ALWAYS) + constraints.Ignore = pv.Ignore_IGNORE_ALWAYS.Enum() } } @@ -105,7 +105,7 @@ func translateRule( return true } else if pgvDesc.Name() == "ignore_empty" && pgvDesc.Kind() == protoreflect.BoolKind && value.Bool() { // old `ignore_empty` fields on the type rules need to be lifted to the top level - constraints.Ignore = toPointer(pv.Ignore_IGNORE_IF_UNPOPULATED) + constraints.Ignore = pv.Ignore_IGNORE_IF_UNPOPULATED.Enum() return true } @@ -144,7 +144,3 @@ func translateRule( } return true } - -func toPointer[T any](value T) *T { - return &value -} diff --git a/legacy/translate_test.go b/legacy/translate_test.go index 2c53630..565aa56 100644 --- a/legacy/translate_test.go +++ b/legacy/translate_test.go @@ -113,7 +113,7 @@ func TestTranslateFieldOptions(t *testing.T) { msg: &examplev1.LegacySkipped{}, field: "x", ex: &validate.FieldConstraints{ - Ignore: toPointer(validate.Ignore_IGNORE_ALWAYS), + Ignore: validate.Ignore_IGNORE_ALWAYS.Enum(), }, }, { @@ -200,7 +200,7 @@ func TestTranslateFieldOptions(t *testing.T) { msg: &examplev1.LegacyIgnoreEmpty{}, field: "x", ex: &validate.FieldConstraints{ - Ignore: toPointer(validate.Ignore_IGNORE_IF_UNPOPULATED), + Ignore: validate.Ignore_IGNORE_IF_UNPOPULATED.Enum(), Type: &validate.FieldConstraints_Int32{ Int32: &validate.Int32Rules{ GreaterThan: &validate.Int32Rules_Gt{