ptr.go 330 B

12345678910111213141516171819202122
  1. package types
  2. // The pointer type that will never panic
  3. // and that forces you to check if it is
  4. // valid.
  5. /*type SafePtr[V any] struct {
  6. ptr *V
  7. }
  8. func NewSafePtr[V any]() SafePtr[V] {
  9. return
  10. }
  11. func (ptr SafePtr[V]) GotV() (V, bool) {
  12. var buf [1]V
  13. if ptr.ptr == nil {
  14. return buf[0], false
  15. }
  16. return *ptr.ptr, true
  17. }*/