From a748d40745611b471ee2a8dd79656aaa174eb03c Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 19 Feb 2025 00:25:00 +0900 Subject: app: store values with string representation Improves code readability without changing memory layout. Signed-off-by: Ophestra --- internal/app/strings.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 internal/app/strings.go (limited to 'internal/app/strings.go') diff --git a/internal/app/strings.go b/internal/app/strings.go new file mode 100644 index 00000000..19f6ea8e --- /dev/null +++ b/internal/app/strings.go @@ -0,0 +1,19 @@ +package app + +import ( + "strconv" + + "git.gensokyo.uk/security/fortify/fst" +) + +func newInt(v int) *stringPair[int] { return &stringPair[int]{v, strconv.Itoa(v)} } +func newID(id *fst.ID) *stringPair[fst.ID] { return &stringPair[fst.ID]{*id, id.String()} } + +// stringPair stores a value and its string representation. +type stringPair[T comparable] struct { + v T + s string +} + +func (s *stringPair[T]) unwrap() T { return s.v } +func (s *stringPair[T]) String() string { return s.s } -- cgit v1.3.1