ptr.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package ptr
  2. import "time"
  3. // Int returns pointer to provided value
  4. func Int(v int) *int { return &v }
  5. // Int8 returns pointer to provided value
  6. func Int8(v int8) *int8 { return &v }
  7. // Int16 returns pointer to provided value
  8. func Int16(v int16) *int16 { return &v }
  9. // Int32 returns pointer to provided value
  10. func Int32(v int32) *int32 { return &v }
  11. // Int64 returns pointer to provided value
  12. func Int64(v int64) *int64 { return &v }
  13. // Uint returns pointer to provided value
  14. func Uint(v uint) *uint { return &v }
  15. // Uint8 returns pointer to provided value
  16. func Uint8(v uint8) *uint8 { return &v }
  17. // Uint16 returns pointer to provided value
  18. func Uint16(v uint16) *uint16 { return &v }
  19. // Uint32 returns pointer to provided value
  20. func Uint32(v uint32) *uint32 { return &v }
  21. // Uint64 returns pointer to provided value
  22. func Uint64(v uint64) *uint64 { return &v }
  23. // Float32 returns pointer to provided value
  24. func Float32(v float32) *float32 { return &v }
  25. // Float64 returns pointer to provided value
  26. func Float64(v float64) *float64 { return &v }
  27. // Bool returns pointer to provided value
  28. func Bool(v bool) *bool { return &v }
  29. // String returns pointer to provided value
  30. func String(v string) *string { return &v }
  31. // Byte returns pointer to provided value
  32. func Byte(v byte) *byte { return &v }
  33. // Rune returns pointer to provided value
  34. func Rune(v rune) *rune { return &v }
  35. // Complex64 returns pointer to provided value
  36. func Complex64(v complex64) *complex64 { return &v }
  37. // Complex128 returns pointer to provided value
  38. func Complex128(v complex128) *complex128 { return &v }
  39. // Time returns pointer to provided value
  40. func Time(v time.Time) *time.Time { return &v }
  41. // Duration returns pointer to provided value
  42. func Duration(v time.Duration) *time.Duration { return &v }
  43. // T returns pointer to provided value
  44. func T[T any](v T) *T { return &v }
  45. // From returns value from pointer
  46. func From[T any](v *T) T {
  47. if v == nil {
  48. return *new(T)
  49. }
  50. return *v
  51. }