diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-02-19 00:25:00 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-02-19 00:25:00 +0900 |
| commit | a748d40745611b471ee2a8dd79656aaa174eb03c (patch) | |
| tree | 6734d036b37ebd40798578a60cf54c2527515a60 /internal/app/strings.go | |
| parent | 648e1d641a8b0ae7c5bc4899f84b884d4335c97f (diff) | |
app: store values with string representation
Improves code readability without changing memory layout.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/strings.go')
| -rw-r--r-- | internal/app/strings.go | 19 |
1 files changed, 19 insertions, 0 deletions
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 } |
