mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-01 04:24:19 +00:00
json/option: Add helper Optional[T] type
This commit is contained in:
parent
c40c6b8021
commit
af0a612eca
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/diamondburned/arikawa/v3
|
||||
|
||||
go 1.16
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gorilla/schema v1.4.1
|
||||
|
|
|
@ -4,3 +4,17 @@
|
|||
// To generate pointerrized primitives, there are helper functions NewT() for
|
||||
// each option type.
|
||||
package option
|
||||
|
||||
// Optional wraps a type to make it omittable.
|
||||
type Optional[T any] *T
|
||||
|
||||
// Some creates a new Optional with the value of the passed type.
|
||||
func Some[T any](v T) Optional[T] {
|
||||
return &v
|
||||
}
|
||||
|
||||
// PtrTo creates a pointer to the passed value.
|
||||
// It is like [Some], except it returns *T directly rather than Optional[T].
|
||||
func PtrTo[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue