1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: fix copylocks warning in Optional struct methods

This commit is contained in:
dudaodong
2024-02-19 10:22:28 +08:00
parent 9f7b416a8d
commit 9fd0603f4a

View File

@@ -7,17 +7,17 @@ import (
// Optional is a type that may or may not contain a non-nil value.
type Optional[T any] struct {
value *T
mu sync.RWMutex
mu *sync.RWMutex
}
// Empty returns an empty Optional instance.
func Empty[T any]() Optional[T] {
return Optional[T]{}
return Optional[T]{mu: &sync.RWMutex{}}
}
// Of returns an Optional with a non-nil value.
func Of[T any](value T) Optional[T] {
return Optional[T]{value: &value}
return Optional[T]{value: &value, mu: &sync.RWMutex{}}
}
// OfNullable returns an Optional for a given value, which may be nil.
@@ -25,7 +25,7 @@ func OfNullable[T any](value *T) Optional[T] {
if value == nil {
return Empty[T]()
}
return Optional[T]{value: value}
return Optional[T]{value: value, mu: &sync.RWMutex{}}
}
// IsPresent checks if there is a value present.