diff --git a/bool.go b/bool.go index 880ffa2..66bd13e 100644 --- a/bool.go +++ b/bool.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:52.312823 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewBool(v bool) Bool { return Bool{&v} } +// NewBoolFromPtr creates an optional.Bool from a bool pointer. +func NewBoolFromPtr(v *bool) Bool { + if v == nil { + return Bool{} + } + return NewBool(*v) +} + // Set sets the bool value. func (b *Bool) Set(v bool) { b.value = &v } +// ToPtr returns a *bool of the value or nil if not present. +func (b Bool) ToPtr() *bool { + if !b.Present() { + return nil + } + v := *b.value + return &v +} + // Get returns the bool value or an error if not present. func (b Bool) Get() (bool, error) { if !b.Present() { diff --git a/byte.go b/byte.go index d4478d7..bc199e5 100644 --- a/byte.go +++ b/byte.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:52.752446 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewByte(v byte) Byte { return Byte{&v} } +// NewByteFromPtr creates an optional.Byte from a byte pointer. +func NewByteFromPtr(v *byte) Byte { + if v == nil { + return Byte{} + } + return NewByte(*v) +} + // Set sets the byte value. func (b *Byte) Set(v byte) { b.value = &v } +// ToPtr returns a *byte of the value or nil if not present. +func (b Byte) ToPtr() *byte { + if !b.Present() { + return nil + } + v := *b.value + return &v +} + // Get returns the byte value or an error if not present. func (b Byte) Get() (byte, error) { if !b.Present() { diff --git a/cmd/optional/main.go b/cmd/optional/main.go index 1eceb29..1784574 100644 --- a/cmd/optional/main.go +++ b/cmd/optional/main.go @@ -146,11 +146,28 @@ func New{{ .OutputName }}(v {{ .TypeName }}) {{ .OutputName }} { return {{ .OutputName }}{&v} } +// New{{ .OutputName }}FromPtr creates an optional.{{ .OutputName }} from a {{ .TypeName }} pointer. +func New{{ .OutputName }}FromPtr(v *{{ .TypeName }}) {{ .OutputName }} { + if v == nil { + return {{ .OutputName }}{} + } + return New{{ .OutputName }}(*v) +} + // Set sets the {{ .TypeName }} value. func ({{ .VariableName }} *{{ .OutputName }}) Set(v {{ .TypeName }}) { {{ .VariableName }}.value = &v } +// ToPtr returns a *{{ .TypeName }} of the value or nil if not present. +func ({{ .VariableName }} {{ .OutputName }}) ToPtr() *{{ .TypeName }} { + if !{{ .VariableName }}.Present() { + return nil + } + v := *{{ .VariableName }}.value + return &v +} + // Get returns the {{ .TypeName }} value or an error if not present. func ({{ .VariableName }} {{ .OutputName }}) Get() ({{ .TypeName }}, error) { if !{{ .VariableName }}.Present() { diff --git a/cmd/optional/testdata/optional_bar.go b/cmd/optional/testdata/optional_bar.go index 0f970b2..5024925 100644 --- a/cmd/optional/testdata/optional_bar.go +++ b/cmd/optional/testdata/optional_bar.go @@ -17,11 +17,28 @@ func NewoptionalBar(v bar) optionalBar { return optionalBar{&v} } +// NewoptionalBarFromPtr creates an optional.optionalBar from a bar pointer. +func NewoptionalBarFromPtr(v *bar) optionalBar { + if v == nil { + return optionalBar{} + } + return NewoptionalBar(*v) +} + // Set sets the bar value. func (o *optionalBar) Set(v bar) { o.value = &v } +// ToPtr returns a *bar of the value or nil if not present. +func (o optionalBar) ToPtr() *bar { + if !o.Present() { + return nil + } + v := *o.value + return &v +} + // Get returns the bar value or an error if not present. func (o optionalBar) Get() (bar, error) { if !o.Present() { diff --git a/cmd/optional/testdata/optional_foo.go b/cmd/optional/testdata/optional_foo.go index c3639c6..3d133ba 100644 --- a/cmd/optional/testdata/optional_foo.go +++ b/cmd/optional/testdata/optional_foo.go @@ -17,11 +17,28 @@ func NewOptionalFoo(v Foo) OptionalFoo { return OptionalFoo{&v} } +// NewOptionalFooFromPtr creates an optional.OptionalFoo from a Foo pointer. +func NewOptionalFooFromPtr(v *Foo) OptionalFoo { + if v == nil { + return OptionalFoo{} + } + return NewOptionalFoo(*v) +} + // Set sets the Foo value. func (o *OptionalFoo) Set(v Foo) { o.value = &v } +// ToPtr returns a *Foo of the value or nil if not present. +func (o OptionalFoo) ToPtr() *Foo { + if !o.Present() { + return nil + } + v := *o.value + return &v +} + // Get returns the Foo value or an error if not present. func (o OptionalFoo) Get() (Foo, error) { if !o.Present() { diff --git a/cmd/optional/testdata/string.go b/cmd/optional/testdata/string.go index 4dbde1e..e5b4027 100644 --- a/cmd/optional/testdata/string.go +++ b/cmd/optional/testdata/string.go @@ -17,11 +17,28 @@ func NewString(v string) String { return String{&v} } +// NewStringFromPtr creates an optional.String from a string pointer. +func NewStringFromPtr(v *string) String { + if v == nil { + return String{} + } + return NewString(*v) +} + // Set sets the string value. func (s *String) Set(v string) { s.value = &v } +// ToPtr returns a *string of the value or nil if not present. +func (s String) ToPtr() *string { + if !s.Present() { + return nil + } + v := *s.value + return &v +} + // Get returns the string value or an error if not present. func (s String) Get() (string, error) { if !s.Present() { diff --git a/complex128.go b/complex128.go index 099a98b..5a31ad9 100644 --- a/complex128.go +++ b/complex128.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:53.141535 +0000 UTC +// Code generated by 'go generate' package optional @@ -17,11 +16,28 @@ func NewComplex128(v complex128) Complex128 { return Complex128{&v} } +// NewComplex128FromPtr creates an optional.Complex128 from a complex128 pointer. +func NewComplex128FromPtr(v *complex128) Complex128 { + if v == nil { + return Complex128{} + } + return NewComplex128(*v) +} + // Set sets the complex128 value. func (c *Complex128) Set(v complex128) { c.value = &v } +// ToPtr returns a *complex128 of the value or nil if not present. +func (c Complex128) ToPtr() *complex128 { + if !c.Present() { + return nil + } + v := *c.value + return &v +} + // Get returns the complex128 value or an error if not present. func (c Complex128) Get() (complex128, error) { if !c.Present() { diff --git a/complex64.go b/complex64.go index d1298b4..7d06bcc 100644 --- a/complex64.go +++ b/complex64.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:53.525719 +0000 UTC +// Code generated by 'go generate' package optional @@ -17,11 +16,28 @@ func NewComplex64(v complex64) Complex64 { return Complex64{&v} } +// NewComplex64FromPtr creates an optional.Complex64 from a complex64 pointer. +func NewComplex64FromPtr(v *complex64) Complex64 { + if v == nil { + return Complex64{} + } + return NewComplex64(*v) +} + // Set sets the complex64 value. func (c *Complex64) Set(v complex64) { c.value = &v } +// ToPtr returns a *complex64 of the value or nil if not present. +func (c Complex64) ToPtr() *complex64 { + if !c.Present() { + return nil + } + v := *c.value + return &v +} + // Get returns the complex64 value or an error if not present. func (c Complex64) Get() (complex64, error) { if !c.Present() { diff --git a/error.go b/error.go index d90d7bc..5e8d0e6 100644 --- a/error.go +++ b/error.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:53.917031 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewError(v error) Error { return Error{&v} } +// NewErrorFromPtr creates an optional.Error from a error pointer. +func NewErrorFromPtr(v *error) Error { + if v == nil { + return Error{} + } + return NewError(*v) +} + // Set sets the error value. func (e *Error) Set(v error) { e.value = &v } +// ToPtr returns a *error of the value or nil if not present. +func (e Error) ToPtr() *error { + if !e.Present() { + return nil + } + v := *e.value + return &v +} + // Get returns the error value or an error if not present. func (e Error) Get() (error, error) { if !e.Present() { diff --git a/float32.go b/float32.go index c0545d8..c94121b 100644 --- a/float32.go +++ b/float32.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:54.315544 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewFloat32(v float32) Float32 { return Float32{&v} } +// NewFloat32FromPtr creates an optional.Float32 from a float32 pointer. +func NewFloat32FromPtr(v *float32) Float32 { + if v == nil { + return Float32{} + } + return NewFloat32(*v) +} + // Set sets the float32 value. func (f *Float32) Set(v float32) { f.value = &v } +// ToPtr returns a *float32 of the value or nil if not present. +func (f Float32) ToPtr() *float32 { + if !f.Present() { + return nil + } + v := *f.value + return &v +} + // Get returns the float32 value or an error if not present. func (f Float32) Get() (float32, error) { if !f.Present() { diff --git a/float64.go b/float64.go index 17fd2c8..935750d 100644 --- a/float64.go +++ b/float64.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:54.698931 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewFloat64(v float64) Float64 { return Float64{&v} } +// NewFloat64FromPtr creates an optional.Float64 from a float64 pointer. +func NewFloat64FromPtr(v *float64) Float64 { + if v == nil { + return Float64{} + } + return NewFloat64(*v) +} + // Set sets the float64 value. func (f *Float64) Set(v float64) { f.value = &v } +// ToPtr returns a *float64 of the value or nil if not present. +func (f Float64) ToPtr() *float64 { + if !f.Present() { + return nil + } + v := *f.value + return &v +} + // Get returns the float64 value or an error if not present. func (f Float64) Get() (float64, error) { if !f.Present() { diff --git a/int.go b/int.go index 0eca2cc..92b1334 100644 --- a/int.go +++ b/int.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:55.077372 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewInt(v int) Int { return Int{&v} } +// NewIntFromPtr creates an optional.Int from a int pointer. +func NewIntFromPtr(v *int) Int { + if v == nil { + return Int{} + } + return NewInt(*v) +} + // Set sets the int value. func (i *Int) Set(v int) { i.value = &v } +// ToPtr returns a *int of the value or nil if not present. +func (i Int) ToPtr() *int { + if !i.Present() { + return nil + } + v := *i.value + return &v +} + // Get returns the int value or an error if not present. func (i Int) Get() (int, error) { if !i.Present() { diff --git a/int16.go b/int16.go index e8a0f89..05286d6 100644 --- a/int16.go +++ b/int16.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:55.464815 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewInt16(v int16) Int16 { return Int16{&v} } +// NewInt16FromPtr creates an optional.Int16 from a int16 pointer. +func NewInt16FromPtr(v *int16) Int16 { + if v == nil { + return Int16{} + } + return NewInt16(*v) +} + // Set sets the int16 value. func (i *Int16) Set(v int16) { i.value = &v } +// ToPtr returns a *int16 of the value or nil if not present. +func (i Int16) ToPtr() *int16 { + if !i.Present() { + return nil + } + v := *i.value + return &v +} + // Get returns the int16 value or an error if not present. func (i Int16) Get() (int16, error) { if !i.Present() { diff --git a/int32.go b/int32.go index df62918..75040ef 100644 --- a/int32.go +++ b/int32.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:55.878008 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewInt32(v int32) Int32 { return Int32{&v} } +// NewInt32FromPtr creates an optional.Int32 from a int32 pointer. +func NewInt32FromPtr(v *int32) Int32 { + if v == nil { + return Int32{} + } + return NewInt32(*v) +} + // Set sets the int32 value. func (i *Int32) Set(v int32) { i.value = &v } +// ToPtr returns a *int32 of the value or nil if not present. +func (i Int32) ToPtr() *int32 { + if !i.Present() { + return nil + } + v := *i.value + return &v +} + // Get returns the int32 value or an error if not present. func (i Int32) Get() (int32, error) { if !i.Present() { diff --git a/int64.go b/int64.go index 1f6a0e0..b131bcd 100644 --- a/int64.go +++ b/int64.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:56.588737 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewInt64(v int64) Int64 { return Int64{&v} } +// NewInt64FromPtr creates an optional.Int64 from a int64 pointer. +func NewInt64FromPtr(v *int64) Int64 { + if v == nil { + return Int64{} + } + return NewInt64(*v) +} + // Set sets the int64 value. func (i *Int64) Set(v int64) { i.value = &v } +// ToPtr returns a *int64 of the value or nil if not present. +func (i Int64) ToPtr() *int64 { + if !i.Present() { + return nil + } + v := *i.value + return &v +} + // Get returns the int64 value or an error if not present. func (i Int64) Get() (int64, error) { if !i.Present() { diff --git a/int8.go b/int8.go index db58a8c..ed94591 100644 --- a/int8.go +++ b/int8.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:57.374933 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewInt8(v int8) Int8 { return Int8{&v} } +// NewInt8FromPtr creates an optional.Int8 from a int8 pointer. +func NewInt8FromPtr(v *int8) Int8 { + if v == nil { + return Int8{} + } + return NewInt8(*v) +} + // Set sets the int8 value. func (i *Int8) Set(v int8) { i.value = &v } +// ToPtr returns a *int8 of the value or nil if not present. +func (i Int8) ToPtr() *int8 { + if !i.Present() { + return nil + } + v := *i.value + return &v +} + // Get returns the int8 value or an error if not present. func (i Int8) Get() (int8, error) { if !i.Present() { diff --git a/int_test.go b/int_test.go index efe5fc6..0ff015c 100644 --- a/int_test.go +++ b/int_test.go @@ -7,6 +7,28 @@ import ( "github.com/stretchr/testify/assert" ) +func TestInt_NewIntFromPtr_NotNil(t *testing.T) { + i := 42 + p := &i + o := NewIntFromPtr(p) + + v, err := o.Get() + assert.True(t, o.Present()) + assert.NoError(t, err) + assert.Equal(t, 42, v) + assert.True(t, p != o.value, "expect return pointer to be different from embedded pointer") +} + +func TestInt_NewIntFromPtr_Nil(t *testing.T) { + o := NewIntFromPtr(nil) + var zero int + + v, err := o.Get() + assert.False(t, o.Present()) + assert.Error(t, err) + assert.Equal(t, zero, v) +} + func TestInt_Get_Present(t *testing.T) { o := NewInt(42) diff --git a/rune.go b/rune.go index 6d93bb6..50d1753 100644 --- a/rune.go +++ b/rune.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:57.770327 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewRune(v rune) Rune { return Rune{&v} } +// NewRuneFromPtr creates an optional.Rune from a rune pointer. +func NewRuneFromPtr(v *rune) Rune { + if v == nil { + return Rune{} + } + return NewRune(*v) +} + // Set sets the rune value. func (r *Rune) Set(v rune) { r.value = &v } +// ToPtr returns a *rune of the value or nil if not present. +func (r Rune) ToPtr() *rune { + if !r.Present() { + return nil + } + v := *r.value + return &v +} + // Get returns the rune value or an error if not present. func (r Rune) Get() (rune, error) { if !r.Present() { diff --git a/string.go b/string.go index 2b107ad..e5b4027 100644 --- a/string.go +++ b/string.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:58.455478 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewString(v string) String { return String{&v} } +// NewStringFromPtr creates an optional.String from a string pointer. +func NewStringFromPtr(v *string) String { + if v == nil { + return String{} + } + return NewString(*v) +} + // Set sets the string value. func (s *String) Set(v string) { s.value = &v } +// ToPtr returns a *string of the value or nil if not present. +func (s String) ToPtr() *string { + if !s.Present() { + return nil + } + v := *s.value + return &v +} + // Get returns the string value or an error if not present. func (s String) Get() (string, error) { if !s.Present() { diff --git a/string_test.go b/string_test.go index 52f19e8..eed1b13 100644 --- a/string_test.go +++ b/string_test.go @@ -7,6 +7,27 @@ import ( "github.com/stretchr/testify/assert" ) +func TestString_NewStringFromPtr_NotNil(t *testing.T) { + s := "foo" + p := &s + o := NewStringFromPtr(p) + + v, err := o.Get() + assert.True(t, o.Present()) + assert.NoError(t, err) + assert.Equal(t, "foo", v) + assert.True(t, p != o.value, "expect return pointer to be different from embedded pointer") +} + +func TestString_NewStringFromPtr_Nil(t *testing.T) { + o := NewStringFromPtr(nil) + + v, err := o.Get() + assert.False(t, o.Present()) + assert.Error(t, err) + assert.Equal(t, "", v) +} + func TestString_Get_Present(t *testing.T) { o := NewString("foo") @@ -79,6 +100,22 @@ func TestString_If_NotPresent(t *testing.T) { assert.False(t, canary) } +func TestString_ToPtr_NotNil(t *testing.T) { + o := NewString("foo") + + p := o.ToPtr() + assert.NotNil(t, p) + assert.Equal(t, "foo", *p) + assert.True(t, p != o.value, "expect return pointer to be different from embedded pointer") +} + +func TestString_ToPtr_Nil(t *testing.T) { + o := String{} + + p := o.ToPtr() + assert.Nil(t, p) +} + func TestString_MarshalJSON(t *testing.T) { type fields struct { WithValue String diff --git a/uint.go b/uint.go index 96223a8..a8218ed 100644 --- a/uint.go +++ b/uint.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:58.844644 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewUint(v uint) Uint { return Uint{&v} } +// NewUintFromPtr creates an optional.Uint from a uint pointer. +func NewUintFromPtr(v *uint) Uint { + if v == nil { + return Uint{} + } + return NewUint(*v) +} + // Set sets the uint value. func (u *Uint) Set(v uint) { u.value = &v } +// ToPtr returns a *uint of the value or nil if not present. +func (u Uint) ToPtr() *uint { + if !u.Present() { + return nil + } + v := *u.value + return &v +} + // Get returns the uint value or an error if not present. func (u Uint) Get() (uint, error) { if !u.Present() { diff --git a/uint16.go b/uint16.go index d79e595..b9c6656 100644 --- a/uint16.go +++ b/uint16.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:59.22585 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewUint16(v uint16) Uint16 { return Uint16{&v} } +// NewUint16FromPtr creates an optional.Uint16 from a uint16 pointer. +func NewUint16FromPtr(v *uint16) Uint16 { + if v == nil { + return Uint16{} + } + return NewUint16(*v) +} + // Set sets the uint16 value. func (u *Uint16) Set(v uint16) { u.value = &v } +// ToPtr returns a *uint16 of the value or nil if not present. +func (u Uint16) ToPtr() *uint16 { + if !u.Present() { + return nil + } + v := *u.value + return &v +} + // Get returns the uint16 value or an error if not present. func (u Uint16) Get() (uint16, error) { if !u.Present() { diff --git a/uint32.go b/uint32.go index cefc35e..007771c 100644 --- a/uint32.go +++ b/uint32.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:59.609003 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewUint32(v uint32) Uint32 { return Uint32{&v} } +// NewUint32FromPtr creates an optional.Uint32 from a uint32 pointer. +func NewUint32FromPtr(v *uint32) Uint32 { + if v == nil { + return Uint32{} + } + return NewUint32(*v) +} + // Set sets the uint32 value. func (u *Uint32) Set(v uint32) { u.value = &v } +// ToPtr returns a *uint32 of the value or nil if not present. +func (u Uint32) ToPtr() *uint32 { + if !u.Present() { + return nil + } + v := *u.value + return &v +} + // Get returns the uint32 value or an error if not present. func (u Uint32) Get() (uint32, error) { if !u.Present() { diff --git a/uint64.go b/uint64.go index db7a98d..af1e499 100644 --- a/uint64.go +++ b/uint64.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:21:59.988145 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewUint64(v uint64) Uint64 { return Uint64{&v} } +// NewUint64FromPtr creates an optional.Uint64 from a uint64 pointer. +func NewUint64FromPtr(v *uint64) Uint64 { + if v == nil { + return Uint64{} + } + return NewUint64(*v) +} + // Set sets the uint64 value. func (u *Uint64) Set(v uint64) { u.value = &v } +// ToPtr returns a *uint64 of the value or nil if not present. +func (u Uint64) ToPtr() *uint64 { + if !u.Present() { + return nil + } + v := *u.value + return &v +} + // Get returns the uint64 value or an error if not present. func (u Uint64) Get() (uint64, error) { if !u.Present() { diff --git a/uint8.go b/uint8.go index 8a281f8..1cf6f1a 100644 --- a/uint8.go +++ b/uint8.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:22:00.389367 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewUint8(v uint8) Uint8 { return Uint8{&v} } +// NewUint8FromPtr creates an optional.Uint8 from a uint8 pointer. +func NewUint8FromPtr(v *uint8) Uint8 { + if v == nil { + return Uint8{} + } + return NewUint8(*v) +} + // Set sets the uint8 value. func (u *Uint8) Set(v uint8) { u.value = &v } +// ToPtr returns a *uint8 of the value or nil if not present. +func (u Uint8) ToPtr() *uint8 { + if !u.Present() { + return nil + } + v := *u.value + return &v +} + // Get returns the uint8 value or an error if not present. func (u Uint8) Get() (uint8, error) { if !u.Present() { diff --git a/uintptr.go b/uintptr.go index deea7aa..81afca4 100644 --- a/uintptr.go +++ b/uintptr.go @@ -1,5 +1,4 @@ -// Code generated by go generate -// This file was generated by robots at 2021-05-04 14:22:00.780925 +0000 UTC +// Code generated by 'go generate' package optional @@ -18,11 +17,28 @@ func NewUintptr(v uintptr) Uintptr { return Uintptr{&v} } +// NewUintptrFromPtr creates an optional.Uintptr from a uintptr pointer. +func NewUintptrFromPtr(v *uintptr) Uintptr { + if v == nil { + return Uintptr{} + } + return NewUintptr(*v) +} + // Set sets the uintptr value. func (u *Uintptr) Set(v uintptr) { u.value = &v } +// ToPtr returns a *uintptr of the value or nil if not present. +func (u Uintptr) ToPtr() *uintptr { + if !u.Present() { + return nil + } + v := *u.value + return &v +} + // Get returns the uintptr value or an error if not present. func (u Uintptr) Get() (uintptr, error) { if !u.Present() {