aboutsummaryrefslogtreecommitdiff
path: root/lib/uuidv7/uuidv7.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uuidv7/uuidv7.go')
-rw-r--r--lib/uuidv7/uuidv7.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/uuidv7/uuidv7.go b/lib/uuidv7/uuidv7.go
index 5a6b6e03..6870b562 100644
--- a/lib/uuidv7/uuidv7.go
+++ b/lib/uuidv7/uuidv7.go
@@ -77,6 +77,27 @@ func (id UUIDv7) Bytes() (data []byte) {
return data
}
+// Equal returns nil if id and v are equals.
+// This method implements [git.sr.ht/~shulhan/pakakeh.go/lib/reflect.Equaler]
+// interface.
+func (id *UUIDv7) Equal(v any) (err error) {
+ ptr, ok := v.(*UUIDv7)
+ if !ok {
+ other, ok := v.(UUIDv7)
+ if !ok {
+ return fmt.Errorf(`uuidv7: Equal: want type %T, got %T`, &id, v)
+ }
+ ptr = &other
+ }
+ if id.high != ptr.high {
+ return fmt.Errorf(`uuidv7: not equal, want %s, got %s`, id.String(), ptr.String())
+ }
+ if id.low != ptr.low {
+ return fmt.Errorf(`uuidv7: not equal, want %s, got %s`, id.String(), ptr.String())
+ }
+ return nil
+}
+
// IsZero returns true if all bits is zero.
func (id UUIDv7) IsZero() bool {
return id.high == 0 && id.low == 0