optional

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2021 License: MIT Imports: 4 Imported by: 5

README

optional

Go Report Card Build Status Go docs

go get 4d63.com/optional
import 4d63.com/optional

Package optional exports types that wrap the builtin types (int, bool, etc) to represent the lack of value. The types guarantee safety by requiring the developer to unwrap them to get to the inner value. This prevents a nil value being operated on. Optionals marshal to XML and JSON like their underlying type, and omitempty works just like their wrapped type would with a pointer, but without the use of pointers.

These types are an alternative to using pointers, zero values, or similar null wrapper packages. Unlike similar solutions these will omit correctly from XML and JSON without the use of pointers and the compiler will ensure their value is not used when empty.

The package also contains a template that you can use with go generate to create optional types for your own types. See below for instructions on how to use the template.

Examples

Wrap a pointer in an optional:

var i *int = ...
o := optional.OfIntPtr(i)

Unwrap it safely:

o.If(func(i int) {
	// called if o is not empty
})

if _, ok := o.Get(); ok {
	// ok is true if o is not empty
}

Or get it's value with a fallback to a default:

_ := o.ElseZero() // returns the zero value if empty

_ := o.Else(100) // returns 100 if o is empty

_ := o.ElseFunc(func() {
	// called if o is empty
	return 100
})

XML and JSON are supported out of the box. Use omitempty to omit the field when the optional is empty:

s := struct {
	Int1 optional.Int `json:"int1,omitempty"`
	Int2 optional.Int `json:"int2,omitempty"`
	Int3 optional.Int `json:"int3,omitempty"`
}{
	Int1: optional.EmptyInt(),
	Int2: optional.OfInt(1000),
	Int3: optional.OfIntPtr(nil),
}

output, _ := json.Marshal(s)

// output = {"int2":1000}
Templates

Use the Optional template for your own types by installing gotemplate.

go get github.com/ncw/gotemplate

Then add a go generate comment for your type to any .go file in your package.

//go:generate gotemplate "4d63.com/optional/template" OptionalMyType(MyType)
Examples

See the examples for more approaches to use.

Documentation

See the godoc.

Documentation

Overview

Package optional exports types that wrap the builtin types (int, bool, etc) to represent the lack of value. The types guarantee safety by requiring the developer to unwrap them to get to the inner value. This prevents a nil value being operated on. Optionals marshal to XML and JSON like their underlying type, and omitempty works just like their wrapped type would with a pointer, but without the use of pointers.

These types are an alternative to using pointers, zero values, or similar null wrapper packages. Unlike similar solutions these will omit correctly from XML and JSON without the use of pointers and the compiler will ensure their value is not used when empty.

The package also contains a template that you can use with go generate to create optional types for your own types. See below for instructions on how to use the template.

Examples

Wrap a pointer in an optional:

var i *int = ...
o := optional.OfIntPtr(i)

Unwrap it safely:

o.If(func(i int) {
	// called if o is not empty
})

if _, ok := o.Get(); ok {
	// ok is true if o is not empty
}

Or get it's value with a fallback to a default:

_ := o.ElseZero() // returns the zero value if empty

_ := o.Else(100) // returns 100 if o is empty

_ := o.ElseFunc(func() {
	// called if o is empty
	return 100
})

XML and JSON are supported out of the box. Use `omitempty` to omit the field when the optional is empty:

s := struct {
	Int1 optional.Int `json:"int1,omitempty"`
	Int2 optional.Int `json:"int2,omitempty"`
	Int3 optional.Int `json:"int3,omitempty"`
}{
	Int1: optional.EmptyInt(),
	Int2: optional.OfInt(1000),
	Int3: optional.OfIntPtr(nil),
}

output, _ := json.Marshal(s)

// output = {"int2":1000}

Templates

Use the Optional template for your own types by installing gotemplate.

go get github.com/ncw/gotemplate

Then add a `go generate` comment for your type to any `.go` file in your package.

//go:generate gotemplate "4d63.com/optional/template" OptionalMyType(MyType)

Examples

See the examples for more approaches to use.

Example (Else)
package main

import (
	"fmt"

	"4d63.com/optional"
)

func main() {
	i := 1001
	values := []optional.Int{
		optional.EmptyInt(),
		optional.OfInt(1000),
		optional.OfIntPtr(nil),
		optional.OfIntPtr(&i),
	}

	for _, v := range values {
		fmt.Println(v.Else(1))
	}

}
Output:

1
1000
1
1001
Example (ElseFunc)
package main

import (
	"fmt"

	"4d63.com/optional"
)

func main() {
	i := 1001
	values := []optional.Int{
		optional.EmptyInt(),
		optional.OfInt(1000),
		optional.OfIntPtr(nil),
		optional.OfIntPtr(&i),
	}

	for _, v := range values {
		fmt.Println(v.ElseFunc(func() int {
			return 2
		}))
	}

}
Output:

2
1000
2
1001
Example (ElseZero)
package main

import (
	"fmt"

	"4d63.com/optional"
)

func main() {
	i := 1001
	values := []optional.Int{
		optional.EmptyInt(),
		optional.OfInt(1000),
		optional.OfIntPtr(nil),
		optional.OfIntPtr(&i),
	}

	for _, v := range values {
		fmt.Println(v.ElseZero())
	}

}
Output:

0
1000
0
1001
Example (Get)
package main

import (
	"fmt"

	"4d63.com/optional"
)

func main() {
	i := 1001
	values := []optional.Int{
		optional.EmptyInt(),
		optional.OfInt(1000),
		optional.OfIntPtr(nil),
		optional.OfIntPtr(&i),
	}

	for _, v := range values {
		if i, ok := v.Get(); ok {
			fmt.Println(i)
		}
	}

}
Output:

1000
1001
Example (If)
package main

import (
	"fmt"

	"4d63.com/optional"
)

func main() {
	i := 1001
	values := []optional.Int{
		optional.EmptyInt(),
		optional.OfInt(1000),
		optional.OfIntPtr(nil),
		optional.OfIntPtr(&i),
	}

	for _, v := range values {
		v.If(func(i int) {
			fmt.Println(i)
		})
	}

}
Output:

1000
1001
Example (JsonMarshalEmpty)
package main

import (
	"encoding/json"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		Bool    optional.Bool    `json:"bool"`
		Byte    optional.Byte    `json:"byte"`
		Float32 optional.Float32 `json:"float32"`
		Float64 optional.Float64 `json:"float64"`
		Int16   optional.Int16   `json:"int16"`
		Int32   optional.Int32   `json:"int32"`
		Int64   optional.Int64   `json:"int64"`
		Int     optional.Int     `json:"int"`
		Rune    optional.Rune    `json:"rune"`
		String  optional.String  `json:"string"`
		Time    optional.Time    `json:"time"`
		Uint16  optional.Uint16  `json:"uint16"`
		Uint32  optional.Uint32  `json:"uint32"`
		Uint64  optional.Uint64  `json:"uint64"`
		Uint    optional.Uint    `json:"uint"`
		Uintptr optional.Uintptr `json:"uintptr"`
	}{
		Bool:    optional.EmptyBool(),
		Byte:    optional.EmptyByte(),
		Float32: optional.EmptyFloat32(),
		Float64: optional.EmptyFloat64(),
		Int16:   optional.EmptyInt16(),
		Int32:   optional.EmptyInt32(),
		Int64:   optional.EmptyInt64(),
		Int:     optional.EmptyInt(),
		Rune:    optional.EmptyRune(),
		String:  optional.EmptyString(),
		Time:    optional.EmptyTime(),
		Uint16:  optional.EmptyUint16(),
		Uint32:  optional.EmptyUint32(),
		Uint64:  optional.EmptyUint64(),
		Uint:    optional.EmptyUint(),
		Uintptr: optional.EmptyUintptr(),
	}

	output, _ := json.MarshalIndent(s, "", "  ")
	fmt.Println(string(output))

}
Output:

{
  "bool": false,
  "byte": 0,
  "float32": 0,
  "float64": 0,
  "int16": 0,
  "int32": 0,
  "int64": 0,
  "int": 0,
  "rune": 0,
  "string": "",
  "time": "0001-01-01T00:00:00Z",
  "uint16": 0,
  "uint32": 0,
  "uint64": 0,
  "uint": 0,
  "uintptr": 0
}
Example (JsonMarshalOmitEmpty)
package main

import (
	"encoding/json"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		Bool    optional.Bool    `json:"bool,omitempty"`
		Byte    optional.Byte    `json:"byte,omitempty"`
		Float32 optional.Float32 `json:"float32,omitempty"`
		Float64 optional.Float64 `json:"float64,omitempty"`
		Int16   optional.Int16   `json:"int16,omitempty"`
		Int32   optional.Int32   `json:"int32,omitempty"`
		Int64   optional.Int64   `json:"int64,omitempty"`
		Int     optional.Int     `json:"int,omitempty"`
		Rune    optional.Rune    `json:"rune,omitempty"`
		String  optional.String  `json:"string,omitempty"`
		Time    optional.Time    `json:"time,omitempty"`
		Uint16  optional.Uint16  `json:"uint16,omitempty"`
		Uint32  optional.Uint32  `json:"uint32,omitempty"`
		Uint64  optional.Uint64  `json:"uint64,omitempty"`
		Uint    optional.Uint    `json:"uint,omitempty"`
		Uintptr optional.Uintptr `json:"uintptr,omitempty"`
	}{
		Bool:    optional.EmptyBool(),
		Byte:    optional.EmptyByte(),
		Float32: optional.EmptyFloat32(),
		Float64: optional.EmptyFloat64(),
		Int16:   optional.EmptyInt16(),
		Int32:   optional.EmptyInt32(),
		Int64:   optional.EmptyInt64(),
		Int:     optional.EmptyInt(),
		Rune:    optional.EmptyRune(),
		String:  optional.EmptyString(),
		Time:    optional.EmptyTime(),
		Uint16:  optional.EmptyUint16(),
		Uint32:  optional.EmptyUint32(),
		Uint64:  optional.EmptyUint64(),
		Uint:    optional.EmptyUint(),
		Uintptr: optional.EmptyUintptr(),
	}

	output, _ := json.MarshalIndent(s, "", "  ")
	fmt.Println(string(output))

}
Output:

{}
Example (JsonMarshalPresent)
package main

import (
	"encoding/json"
	"fmt"
	"time"

	"4d63.com/optional"
)

func main() {
	s := struct {
		Bool    optional.Bool    `json:"bool"`
		Byte    optional.Byte    `json:"byte"`
		Float32 optional.Float32 `json:"float32"`
		Float64 optional.Float64 `json:"float64"`
		Int16   optional.Int16   `json:"int16"`
		Int32   optional.Int32   `json:"int32"`
		Int64   optional.Int64   `json:"int64"`
		Int     optional.Int     `json:"int"`
		Rune    optional.Rune    `json:"rune"`
		String  optional.String  `json:"string"`
		Time    optional.Time    `json:"time"`
		Uint16  optional.Uint16  `json:"uint16"`
		Uint32  optional.Uint32  `json:"uint32"`
		Uint64  optional.Uint64  `json:"uint64"`
		Uint    optional.Uint    `json:"uint"`
		Uintptr optional.Uintptr `json:"uintptr"`
	}{
		Bool:    optional.OfBool(true),
		Byte:    optional.OfByte(1),
		Float32: optional.OfFloat32(2.1),
		Float64: optional.OfFloat64(2.2),
		Int16:   optional.OfInt16(3),
		Int32:   optional.OfInt32(4),
		Int64:   optional.OfInt64(5),
		Int:     optional.OfInt(6),
		Rune:    optional.OfRune(7),
		String:  optional.OfString("string"),
		Time:    optional.OfTime(time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)),
		Uint16:  optional.OfUint16(8),
		Uint32:  optional.OfUint32(9),
		Uint64:  optional.OfUint64(10),
		Uint:    optional.OfUint(11),
		Uintptr: optional.OfUintptr(12),
	}

	output, _ := json.MarshalIndent(s, "", "  ")
	fmt.Println(string(output))

}
Output:

{
  "bool": true,
  "byte": 1,
  "float32": 2.1,
  "float64": 2.2,
  "int16": 3,
  "int32": 4,
  "int64": 5,
  "int": 6,
  "rune": 7,
  "string": "string",
  "time": "2006-01-02T15:04:05Z",
  "uint16": 8,
  "uint32": 9,
  "uint64": 10,
  "uint": 11,
  "uintptr": 12
}
Example (JsonUnmarshalEmpty)
package main

import (
	"encoding/json"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		Bool    optional.Bool    `json:"bool"`
		Byte    optional.Byte    `json:"byte"`
		Float32 optional.Float32 `json:"float32"`
		Float64 optional.Float64 `json:"float64"`
		Int16   optional.Int16   `json:"int16"`
		Int32   optional.Int32   `json:"int32"`
		Int64   optional.Int64   `json:"int64"`
		Int     optional.Int     `json:"int"`
		Rune    optional.Rune    `json:"rune"`
		String  optional.String  `json:"string"`
		Time    optional.Time    `json:"time"`
		Uint16  optional.Uint16  `json:"uint16"`
		Uint32  optional.Uint32  `json:"uint32"`
		Uint64  optional.Uint64  `json:"uint64"`
		Uint    optional.Uint    `json:"uint"`
		Uintptr optional.Uintptr `json:"uintptr"`
	}{}

	x := `{}`
	json.Unmarshal([]byte(x), &s)
	fmt.Println("Bool:", s.Bool.IsPresent())
	fmt.Println("Byte:", s.Byte.IsPresent())
	fmt.Println("Float32:", s.Float32.IsPresent())
	fmt.Println("Float64:", s.Float64.IsPresent())
	fmt.Println("Int16:", s.Int16.IsPresent())
	fmt.Println("Int32:", s.Int32.IsPresent())
	fmt.Println("Int64:", s.Int64.IsPresent())
	fmt.Println("Int:", s.Int.IsPresent())
	fmt.Println("Rune:", s.Rune.IsPresent())
	fmt.Println("String:", s.String.IsPresent())
	fmt.Println("Time:", s.Time.IsPresent())
	fmt.Println("Uint16:", s.Uint16.IsPresent())
	fmt.Println("Uint32:", s.Uint32.IsPresent())
	fmt.Println("Uint64:", s.Uint64.IsPresent())
	fmt.Println("Uint64:", s.Uint64.IsPresent())
	fmt.Println("Uint:", s.Uint.IsPresent())
	fmt.Println("Uintptr:", s.Uint.IsPresent())

}
Output:

Bool: false
Byte: false
Float32: false
Float64: false
Int16: false
Int32: false
Int64: false
Int: false
Rune: false
String: false
Time: false
Uint16: false
Uint32: false
Uint64: false
Uint64: false
Uint: false
Uintptr: false
Example (JsonUnmarshalPresent)
package main

import (
	"encoding/json"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		Bool    optional.Bool    `json:"bool"`
		Byte    optional.Byte    `json:"byte"`
		Float32 optional.Float32 `json:"float32"`
		Float64 optional.Float64 `json:"float64"`
		Int16   optional.Int16   `json:"int16"`
		Int32   optional.Int32   `json:"int32"`
		Int64   optional.Int64   `json:"int64"`
		Int     optional.Int     `json:"int"`
		Rune    optional.Rune    `json:"rune"`
		String  optional.String  `json:"string"`
		Time    optional.Time    `json:"time"`
		Uint16  optional.Uint16  `json:"uint16"`
		Uint32  optional.Uint32  `json:"uint32"`
		Uint64  optional.Uint64  `json:"uint64"`
		Uint    optional.Uint    `json:"uint"`
		Uintptr optional.Uintptr `json:"uintptr"`
	}{}

	x := `{
  "bool": false,
  "byte": 0,
  "float32": 0,
  "float64": 0,
  "int16": 0,
  "int32": 0,
  "int64": 0,
  "int": 0,
  "rune": 0,
  "string": "string",
  "time": "0001-01-01T00:00:00Z",
  "uint16": 0,
  "uint32": 0,
  "uint64": 0,
  "uint": 0,
  "uintptr": 0
}`
	json.Unmarshal([]byte(x), &s)
	fmt.Println("Bool:", s.Bool.IsPresent(), s.Bool)
	fmt.Println("Byte:", s.Byte.IsPresent(), s.Byte)
	fmt.Println("Float32:", s.Float32.IsPresent(), s.Float32)
	fmt.Println("Float64:", s.Float64.IsPresent(), s.Float64)
	fmt.Println("Int16:", s.Int16.IsPresent(), s.Int16)
	fmt.Println("Int32:", s.Int32.IsPresent(), s.Int32)
	fmt.Println("Int64:", s.Int64.IsPresent(), s.Int64)
	fmt.Println("Int:", s.Int.IsPresent(), s.Int)
	fmt.Println("Rune:", s.Rune.IsPresent(), s.Rune)
	fmt.Println("String:", s.String.IsPresent(), s.String)
	fmt.Println("Time:", s.Time.IsPresent(), s.Time)
	fmt.Println("Uint16:", s.Uint16.IsPresent(), s.Uint16)
	fmt.Println("Uint32:", s.Uint32.IsPresent(), s.Uint32)
	fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64)
	fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64)
	fmt.Println("Uint:", s.Uint.IsPresent(), s.Uint)
	fmt.Println("Uintptr:", s.Uint.IsPresent(), s.Uint)

}
Output:

Bool: true false
Byte: true 0
Float32: true 0
Float64: true 0
Int16: true 0
Int32: true 0
Int64: true 0
Int: true 0
Rune: true 0
String: true string
Time: true 0001-01-01 00:00:00 +0000 UTC
Uint16: true 0
Uint32: true 0
Uint64: true 0
Uint64: true 0
Uint: true 0
Uintptr: true 0
Example (XmlMarshalEmpty)
package main

import (
	"encoding/xml"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		XMLName xml.Name         `xml:"s"`
		Bool    optional.Bool    `xml:"bool"`
		Byte    optional.Byte    `xml:"byte"`
		Float32 optional.Float32 `xml:"float32"`
		Float64 optional.Float64 `xml:"float64"`
		Int16   optional.Int16   `xml:"int16"`
		Int32   optional.Int32   `xml:"int32"`
		Int64   optional.Int64   `xml:"int64"`
		Int     optional.Int     `xml:"int"`
		Rune    optional.Rune    `xml:"rune"`
		String  optional.String  `xml:"string"`
		Time    optional.Time    `xml:"time"`
		Uint16  optional.Uint16  `xml:"uint16"`
		Uint32  optional.Uint32  `xml:"uint32"`
		Uint64  optional.Uint64  `xml:"uint64"`
		Uint    optional.Uint    `xml:"uint"`
		Uintptr optional.Uintptr `xml:"uintptr"`
	}{
		Bool:    optional.EmptyBool(),
		Byte:    optional.EmptyByte(),
		Float32: optional.EmptyFloat32(),
		Float64: optional.EmptyFloat64(),
		Int16:   optional.EmptyInt16(),
		Int32:   optional.EmptyInt32(),
		Int64:   optional.EmptyInt64(),
		Int:     optional.EmptyInt(),
		Rune:    optional.EmptyRune(),
		String:  optional.EmptyString(),
		Time:    optional.EmptyTime(),
		Uint16:  optional.EmptyUint16(),
		Uint32:  optional.EmptyUint32(),
		Uint64:  optional.EmptyUint64(),
		Uint:    optional.EmptyUint(),
		Uintptr: optional.EmptyUintptr(),
	}

	output, _ := xml.MarshalIndent(s, "", "  ")
	fmt.Println(string(output))

}
Output:

<s>
  <bool>false</bool>
  <byte>0</byte>
  <float32>0</float32>
  <float64>0</float64>
  <int16>0</int16>
  <int32>0</int32>
  <int64>0</int64>
  <int>0</int>
  <rune>0</rune>
  <string></string>
  <time>0001-01-01T00:00:00Z</time>
  <uint16>0</uint16>
  <uint32>0</uint32>
  <uint64>0</uint64>
  <uint>0</uint>
  <uintptr>0</uintptr>
</s>
Example (XmlMarshalOmitEmpty)
package main

import (
	"encoding/xml"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		XMLName xml.Name         `xml:"s"`
		Bool    optional.Bool    `xml:"bool,omitempty"`
		Byte    optional.Byte    `xml:"byte,omitempty"`
		Float32 optional.Float32 `xml:"float32,omitempty"`
		Float64 optional.Float64 `xml:"float64,omitempty"`
		Int16   optional.Int16   `xml:"int16,omitempty"`
		Int32   optional.Int32   `xml:"int32,omitempty"`
		Int64   optional.Int64   `xml:"int64,omitempty"`
		Int     optional.Int     `xml:"int,omitempty"`
		Rune    optional.Rune    `xml:"rune,omitempty"`
		String  optional.String  `xml:"string,omitempty"`
		Time    optional.Time    `xml:"time,omitempty"`
		Uint16  optional.Uint16  `xml:"uint16,omitempty"`
		Uint32  optional.Uint32  `xml:"uint32,omitempty"`
		Uint64  optional.Uint64  `xml:"uint64,omitempty"`
		Uint    optional.Uint    `xml:"uint,omitempty"`
		Uintptr optional.Uintptr `xml:"uintptr,omitempty"`
	}{
		Bool:    optional.EmptyBool(),
		Byte:    optional.EmptyByte(),
		Float32: optional.EmptyFloat32(),
		Float64: optional.EmptyFloat64(),
		Int16:   optional.EmptyInt16(),
		Int32:   optional.EmptyInt32(),
		Int64:   optional.EmptyInt64(),
		Int:     optional.EmptyInt(),
		Rune:    optional.EmptyRune(),
		String:  optional.EmptyString(),
		Time:    optional.EmptyTime(),
		Uint16:  optional.EmptyUint16(),
		Uint32:  optional.EmptyUint32(),
		Uint64:  optional.EmptyUint64(),
		Uint:    optional.EmptyUint(),
		Uintptr: optional.EmptyUintptr(),
	}

	output, _ := xml.MarshalIndent(s, "", "  ")
	fmt.Println(string(output))

}
Output:

<s></s>
Example (XmlMarshalPresent)
package main

import (
	"encoding/xml"
	"fmt"
	"time"

	"4d63.com/optional"
)

func main() {
	s := struct {
		XMLName xml.Name         `xml:"s"`
		Bool    optional.Bool    `xml:"bool"`
		Byte    optional.Byte    `xml:"byte"`
		Float32 optional.Float32 `xml:"float32"`
		Float64 optional.Float64 `xml:"float64"`
		Int16   optional.Int16   `xml:"int16"`
		Int32   optional.Int32   `xml:"int32"`
		Int64   optional.Int64   `xml:"int64"`
		Int     optional.Int     `xml:"int"`
		Rune    optional.Rune    `xml:"rune"`
		String  optional.String  `xml:"string"`
		Time    optional.Time    `xml:"time"`
		Uint16  optional.Uint16  `xml:"uint16"`
		Uint32  optional.Uint32  `xml:"uint32"`
		Uint64  optional.Uint64  `xml:"uint64"`
		Uint    optional.Uint    `xml:"uint"`
		Uintptr optional.Uintptr `xml:"uintptr"`
	}{
		Bool:    optional.OfBool(true),
		Byte:    optional.OfByte(1),
		Float32: optional.OfFloat32(2.1),
		Float64: optional.OfFloat64(2.2),
		Int16:   optional.OfInt16(3),
		Int32:   optional.OfInt32(4),
		Int64:   optional.OfInt64(5),
		Int:     optional.OfInt(6),
		Rune:    optional.OfRune(7),
		String:  optional.OfString("string"),
		Time:    optional.OfTime(time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)),
		Uint16:  optional.OfUint16(8),
		Uint32:  optional.OfUint32(9),
		Uint64:  optional.OfUint64(10),
		Uint:    optional.OfUint(11),
		Uintptr: optional.OfUintptr(12),
	}

	output, _ := xml.MarshalIndent(s, "", "  ")
	fmt.Println(string(output))

}
Output:

<s>
  <bool>true</bool>
  <byte>1</byte>
  <float32>2.1</float32>
  <float64>2.2</float64>
  <int16>3</int16>
  <int32>4</int32>
  <int64>5</int64>
  <int>6</int>
  <rune>7</rune>
  <string>string</string>
  <time>2006-01-02T15:04:05Z</time>
  <uint16>8</uint16>
  <uint32>9</uint32>
  <uint64>10</uint64>
  <uint>11</uint>
  <uintptr>12</uintptr>
</s>
Example (XmlUnmarshalEmpty)
package main

import (
	"encoding/xml"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		XMLName xml.Name         `xml:"s"`
		Bool    optional.Bool    `xml:"bool"`
		Byte    optional.Byte    `xml:"byte"`
		Float32 optional.Float32 `xml:"float32"`
		Float64 optional.Float64 `xml:"float64"`
		Int16   optional.Int16   `xml:"int16"`
		Int32   optional.Int32   `xml:"int32"`
		Int64   optional.Int64   `xml:"int64"`
		Int     optional.Int     `xml:"int"`
		Rune    optional.Rune    `xml:"rune"`
		String  optional.String  `xml:"string"`
		Time    optional.Time    `xml:"time"`
		Uint16  optional.Uint16  `xml:"uint16"`
		Uint32  optional.Uint32  `xml:"uint32"`
		Uint64  optional.Uint64  `xml:"uint64"`
		Uint    optional.Uint    `xml:"uint"`
		Uintptr optional.Uintptr `xml:"uintptr"`
	}{}

	x := `<s></s>`
	xml.Unmarshal([]byte(x), &s)
	fmt.Println("Bool:", s.Bool.IsPresent())
	fmt.Println("Byte:", s.Byte.IsPresent())
	fmt.Println("Float32:", s.Float32.IsPresent())
	fmt.Println("Float64:", s.Float64.IsPresent())
	fmt.Println("Int16:", s.Int16.IsPresent())
	fmt.Println("Int32:", s.Int32.IsPresent())
	fmt.Println("Int64:", s.Int64.IsPresent())
	fmt.Println("Int:", s.Int.IsPresent())
	fmt.Println("Rune:", s.Rune.IsPresent())
	fmt.Println("String:", s.String.IsPresent())
	fmt.Println("Time:", s.Time.IsPresent())
	fmt.Println("Uint16:", s.Uint16.IsPresent())
	fmt.Println("Uint32:", s.Uint32.IsPresent())
	fmt.Println("Uint64:", s.Uint64.IsPresent())
	fmt.Println("Uint64:", s.Uint64.IsPresent())
	fmt.Println("Uint:", s.Uint.IsPresent())
	fmt.Println("Uintptr:", s.Uint.IsPresent())

}
Output:

Bool: false
Byte: false
Float32: false
Float64: false
Int16: false
Int32: false
Int64: false
Int: false
Rune: false
String: false
Time: false
Uint16: false
Uint32: false
Uint64: false
Uint64: false
Uint: false
Uintptr: false
Example (XmlUnmarshalPresent)
package main

import (
	"encoding/xml"
	"fmt"

	"4d63.com/optional"
)

func main() {
	s := struct {
		XMLName xml.Name         `xml:"s"`
		Bool    optional.Bool    `xml:"bool"`
		Byte    optional.Byte    `xml:"byte"`
		Float32 optional.Float32 `xml:"float32"`
		Float64 optional.Float64 `xml:"float64"`
		Int16   optional.Int16   `xml:"int16"`
		Int32   optional.Int32   `xml:"int32"`
		Int64   optional.Int64   `xml:"int64"`
		Int     optional.Int     `xml:"int"`
		Rune    optional.Rune    `xml:"rune"`
		String  optional.String  `xml:"string"`
		Time    optional.Time    `xml:"time"`
		Uint16  optional.Uint16  `xml:"uint16"`
		Uint32  optional.Uint32  `xml:"uint32"`
		Uint64  optional.Uint64  `xml:"uint64"`
		Uint    optional.Uint    `xml:"uint"`
		Uintptr optional.Uintptr `xml:"uintptr"`
	}{}

	x := `<s>
  <bool>false</bool>
  <byte>0</byte>
  <float32>0</float32>
  <float64>0</float64>
  <int16>0</int16>
  <int32>0</int32>
  <int64>0</int64>
  <int>0</int>
  <rune>0</rune>
  <string>string</string>
  <time>0001-01-01T00:00:00Z</time>
  <uint16>0</uint16>
  <uint32>0</uint32>
  <uint64>0</uint64>
  <uint>0</uint>
  <uintptr>0</uintptr>
</s>`
	xml.Unmarshal([]byte(x), &s)
	fmt.Println("Bool:", s.Bool.IsPresent(), s.Bool)
	fmt.Println("Byte:", s.Byte.IsPresent(), s.Byte)
	fmt.Println("Float32:", s.Float32.IsPresent(), s.Float32)
	fmt.Println("Float64:", s.Float64.IsPresent(), s.Float64)
	fmt.Println("Int16:", s.Int16.IsPresent(), s.Int16)
	fmt.Println("Int32:", s.Int32.IsPresent(), s.Int32)
	fmt.Println("Int64:", s.Int64.IsPresent(), s.Int64)
	fmt.Println("Int:", s.Int.IsPresent(), s.Int)
	fmt.Println("Rune:", s.Rune.IsPresent(), s.Rune)
	fmt.Println("String:", s.String.IsPresent(), s.String)
	fmt.Println("Time:", s.Time.IsPresent(), s.Time)
	fmt.Println("Uint16:", s.Uint16.IsPresent(), s.Uint16)
	fmt.Println("Uint32:", s.Uint32.IsPresent(), s.Uint32)
	fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64)
	fmt.Println("Uint64:", s.Uint64.IsPresent(), s.Uint64)
	fmt.Println("Uint:", s.Uint.IsPresent(), s.Uint)
	fmt.Println("Uintptr:", s.Uint.IsPresent(), s.Uint)

}
Output:

Bool: true false
Byte: true 0
Float32: true 0
Float64: true 0
Int16: true 0
Int32: true 0
Int64: true 0
Int: true 0
Rune: true 0
String: true string
Time: true 0001-01-01 00:00:00 +0000 UTC
Uint16: true 0
Uint32: true 0
Uint64: true 0
Uint64: true 0
Uint: true 0
Uintptr: true 0

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool optionalBool

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyBool

func EmptyBool() Bool

Empty returns an empty optional.

func OfBool

func OfBool(value bool) Bool

Of wraps the value in an optional.

func OfBoolPtr

func OfBoolPtr(ptr *bool) Bool

func (Bool) Else

func (o Bool) Else(elseValue bool) (value bool)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Bool) ElseFunc

func (o Bool) ElseFunc(f func() bool) (value bool)

func (Bool) ElseZero

func (o Bool) ElseZero() (value bool)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Bool) Get

func (o Bool) Get() (value bool, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Bool) If

func (o Bool) If(f func(value bool))

If calls the function if there is a value wrapped by this optional.

func (Bool) IsPresent

func (o Bool) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Bool) MarshalJSON

func (o Bool) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Bool) MarshalXML

func (o Bool) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Bool) String

func (o Bool) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Bool) UnmarshalJSON

func (o *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Bool) UnmarshalXML

func (o *Bool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Byte

type Byte optionalByte

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyByte

func EmptyByte() Byte

Empty returns an empty optional.

func OfByte

func OfByte(value byte) Byte

Of wraps the value in an optional.

func OfBytePtr

func OfBytePtr(ptr *byte) Byte

func (Byte) Else

func (o Byte) Else(elseValue byte) (value byte)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Byte) ElseFunc

func (o Byte) ElseFunc(f func() byte) (value byte)

func (Byte) ElseZero

func (o Byte) ElseZero() (value byte)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Byte) Get

func (o Byte) Get() (value byte, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Byte) If

func (o Byte) If(f func(value byte))

If calls the function if there is a value wrapped by this optional.

func (Byte) IsPresent

func (o Byte) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Byte) MarshalJSON

func (o Byte) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Byte) MarshalXML

func (o Byte) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Byte) String

func (o Byte) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Byte) UnmarshalJSON

func (o *Byte) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Byte) UnmarshalXML

func (o *Byte) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Complex128

type Complex128 optionalComplex128

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyComplex128

func EmptyComplex128() Complex128

Empty returns an empty optional.

func OfComplex128

func OfComplex128(value complex128) Complex128

Of wraps the value in an optional.

func OfComplex128Ptr

func OfComplex128Ptr(ptr *complex128) Complex128

func (Complex128) Else

func (o Complex128) Else(elseValue complex128) (value complex128)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Complex128) ElseFunc

func (o Complex128) ElseFunc(f func() complex128) (value complex128)

func (Complex128) ElseZero

func (o Complex128) ElseZero() (value complex128)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Complex128) Get

func (o Complex128) Get() (value complex128, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Complex128) If

func (o Complex128) If(f func(value complex128))

If calls the function if there is a value wrapped by this optional.

func (Complex128) IsPresent

func (o Complex128) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Complex128) MarshalJSON

func (o Complex128) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Complex128) MarshalXML

func (o Complex128) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Complex128) String

func (o Complex128) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Complex128) UnmarshalJSON

func (o *Complex128) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Complex128) UnmarshalXML

func (o *Complex128) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Complex64

type Complex64 optionalComplex64

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyComplex64

func EmptyComplex64() Complex64

Empty returns an empty optional.

func OfComplex64

func OfComplex64(value complex64) Complex64

Of wraps the value in an optional.

func OfComplex64Ptr

func OfComplex64Ptr(ptr *complex64) Complex64

func (Complex64) Else

func (o Complex64) Else(elseValue complex64) (value complex64)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Complex64) ElseFunc

func (o Complex64) ElseFunc(f func() complex64) (value complex64)

func (Complex64) ElseZero

func (o Complex64) ElseZero() (value complex64)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Complex64) Get

func (o Complex64) Get() (value complex64, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Complex64) If

func (o Complex64) If(f func(value complex64))

If calls the function if there is a value wrapped by this optional.

func (Complex64) IsPresent

func (o Complex64) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Complex64) MarshalJSON

func (o Complex64) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Complex64) MarshalXML

func (o Complex64) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Complex64) String

func (o Complex64) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Complex64) UnmarshalJSON

func (o *Complex64) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Complex64) UnmarshalXML

func (o *Complex64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Float32

type Float32 optionalFloat32

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyFloat32

func EmptyFloat32() Float32

Empty returns an empty optional.

func OfFloat32

func OfFloat32(value float32) Float32

Of wraps the value in an optional.

func OfFloat32Ptr

func OfFloat32Ptr(ptr *float32) Float32

func (Float32) Else

func (o Float32) Else(elseValue float32) (value float32)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Float32) ElseFunc

func (o Float32) ElseFunc(f func() float32) (value float32)

func (Float32) ElseZero

func (o Float32) ElseZero() (value float32)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Float32) Get

func (o Float32) Get() (value float32, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Float32) If

func (o Float32) If(f func(value float32))

If calls the function if there is a value wrapped by this optional.

func (Float32) IsPresent

func (o Float32) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Float32) MarshalJSON

func (o Float32) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Float32) MarshalXML

func (o Float32) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Float32) String

func (o Float32) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Float32) UnmarshalJSON

func (o *Float32) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Float32) UnmarshalXML

func (o *Float32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Float64

type Float64 optionalFloat64

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyFloat64

func EmptyFloat64() Float64

Empty returns an empty optional.

func OfFloat64

func OfFloat64(value float64) Float64

Of wraps the value in an optional.

func OfFloat64Ptr

func OfFloat64Ptr(ptr *float64) Float64

func (Float64) Else

func (o Float64) Else(elseValue float64) (value float64)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Float64) ElseFunc

func (o Float64) ElseFunc(f func() float64) (value float64)

func (Float64) ElseZero

func (o Float64) ElseZero() (value float64)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Float64) Get

func (o Float64) Get() (value float64, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Float64) If

func (o Float64) If(f func(value float64))

If calls the function if there is a value wrapped by this optional.

func (Float64) IsPresent

func (o Float64) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Float64) MarshalJSON

func (o Float64) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Float64) MarshalXML

func (o Float64) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Float64) String

func (o Float64) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Float64) UnmarshalJSON

func (o *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Float64) UnmarshalXML

func (o *Float64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Int

type Int optionalInt

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyInt

func EmptyInt() Int

Empty returns an empty optional.

func OfInt

func OfInt(value int) Int

Of wraps the value in an optional.

func OfIntPtr

func OfIntPtr(ptr *int) Int

func (Int) Else

func (o Int) Else(elseValue int) (value int)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Int) ElseFunc

func (o Int) ElseFunc(f func() int) (value int)

func (Int) ElseZero

func (o Int) ElseZero() (value int)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Int) Get

func (o Int) Get() (value int, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Int) If

func (o Int) If(f func(value int))

If calls the function if there is a value wrapped by this optional.

func (Int) IsPresent

func (o Int) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Int) MarshalJSON

func (o Int) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int) MarshalXML

func (o Int) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int) String

func (o Int) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Int) UnmarshalJSON

func (o *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Int) UnmarshalXML

func (o *Int) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Int16

type Int16 optionalInt16

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyInt16

func EmptyInt16() Int16

Empty returns an empty optional.

func OfInt16

func OfInt16(value int16) Int16

Of wraps the value in an optional.

func OfInt16Ptr

func OfInt16Ptr(ptr *int16) Int16

func (Int16) Else

func (o Int16) Else(elseValue int16) (value int16)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Int16) ElseFunc

func (o Int16) ElseFunc(f func() int16) (value int16)

func (Int16) ElseZero

func (o Int16) ElseZero() (value int16)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Int16) Get

func (o Int16) Get() (value int16, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Int16) If

func (o Int16) If(f func(value int16))

If calls the function if there is a value wrapped by this optional.

func (Int16) IsPresent

func (o Int16) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Int16) MarshalJSON

func (o Int16) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int16) MarshalXML

func (o Int16) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int16) String

func (o Int16) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Int16) UnmarshalJSON

func (o *Int16) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Int16) UnmarshalXML

func (o *Int16) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Int32

type Int32 optionalInt32

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyInt32

func EmptyInt32() Int32

Empty returns an empty optional.

func OfInt32

func OfInt32(value int32) Int32

Of wraps the value in an optional.

func OfInt32Ptr

func OfInt32Ptr(ptr *int32) Int32

func (Int32) Else

func (o Int32) Else(elseValue int32) (value int32)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Int32) ElseFunc

func (o Int32) ElseFunc(f func() int32) (value int32)

func (Int32) ElseZero

func (o Int32) ElseZero() (value int32)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Int32) Get

func (o Int32) Get() (value int32, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Int32) If

func (o Int32) If(f func(value int32))

If calls the function if there is a value wrapped by this optional.

func (Int32) IsPresent

func (o Int32) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Int32) MarshalJSON

func (o Int32) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int32) MarshalXML

func (o Int32) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int32) String

func (o Int32) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Int32) UnmarshalJSON

func (o *Int32) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Int32) UnmarshalXML

func (o *Int32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Int64

type Int64 optionalInt64

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyInt64

func EmptyInt64() Int64

Empty returns an empty optional.

func OfInt64

func OfInt64(value int64) Int64

Of wraps the value in an optional.

func OfInt64Ptr

func OfInt64Ptr(ptr *int64) Int64

func (Int64) Else

func (o Int64) Else(elseValue int64) (value int64)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Int64) ElseFunc

func (o Int64) ElseFunc(f func() int64) (value int64)

func (Int64) ElseZero

func (o Int64) ElseZero() (value int64)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Int64) Get

func (o Int64) Get() (value int64, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Int64) If

func (o Int64) If(f func(value int64))

If calls the function if there is a value wrapped by this optional.

func (Int64) IsPresent

func (o Int64) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Int64) MarshalJSON

func (o Int64) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int64) MarshalXML

func (o Int64) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int64) String

func (o Int64) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Int64) UnmarshalJSON

func (o *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Int64) UnmarshalXML

func (o *Int64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Int8

type Int8 optionalInt8

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyInt8

func EmptyInt8() Int8

Empty returns an empty optional.

func OfInt8

func OfInt8(value int8) Int8

Of wraps the value in an optional.

func OfInt8Ptr

func OfInt8Ptr(ptr *int8) Int8

func (Int8) Else

func (o Int8) Else(elseValue int8) (value int8)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Int8) ElseFunc

func (o Int8) ElseFunc(f func() int8) (value int8)

func (Int8) ElseZero

func (o Int8) ElseZero() (value int8)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Int8) Get

func (o Int8) Get() (value int8, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Int8) If

func (o Int8) If(f func(value int8))

If calls the function if there is a value wrapped by this optional.

func (Int8) IsPresent

func (o Int8) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Int8) MarshalJSON

func (o Int8) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int8) MarshalXML

func (o Int8) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Int8) String

func (o Int8) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Int8) UnmarshalJSON

func (o *Int8) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Int8) UnmarshalXML

func (o *Int8) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Rune

type Rune optionalRune

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyRune

func EmptyRune() Rune

Empty returns an empty optional.

func OfRune

func OfRune(value rune) Rune

Of wraps the value in an optional.

func OfRunePtr

func OfRunePtr(ptr *rune) Rune

func (Rune) Else

func (o Rune) Else(elseValue rune) (value rune)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Rune) ElseFunc

func (o Rune) ElseFunc(f func() rune) (value rune)

func (Rune) ElseZero

func (o Rune) ElseZero() (value rune)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Rune) Get

func (o Rune) Get() (value rune, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Rune) If

func (o Rune) If(f func(value rune))

If calls the function if there is a value wrapped by this optional.

func (Rune) IsPresent

func (o Rune) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Rune) MarshalJSON

func (o Rune) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Rune) MarshalXML

func (o Rune) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Rune) String

func (o Rune) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Rune) UnmarshalJSON

func (o *Rune) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Rune) UnmarshalXML

func (o *Rune) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type String

type String optionalString

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyString

func EmptyString() String

Empty returns an empty optional.

func OfString

func OfString(value string) String

Of wraps the value in an optional.

func OfStringPtr

func OfStringPtr(ptr *string) String

func (String) Else

func (o String) Else(elseValue string) (value string)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (String) ElseFunc

func (o String) ElseFunc(f func() string) (value string)

func (String) ElseZero

func (o String) ElseZero() (value string)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (String) Get

func (o String) Get() (value string, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (String) If

func (o String) If(f func(value string))

If calls the function if there is a value wrapped by this optional.

func (String) IsPresent

func (o String) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (String) MarshalJSON

func (o String) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (String) MarshalXML

func (o String) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (String) String

func (o String) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*String) UnmarshalJSON

func (o *String) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*String) UnmarshalXML

func (o *String) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Time

type Time optionalTime

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyTime

func EmptyTime() Time

Empty returns an empty optional.

func OfTime

func OfTime(value time.Time) Time

Of wraps the value in an optional.

func OfTimePtr

func OfTimePtr(ptr *time.Time) Time

func (Time) Else

func (o Time) Else(elseValue time.Time) (value time.Time)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Time) ElseFunc

func (o Time) ElseFunc(f func() time.Time) (value time.Time)

func (Time) ElseZero

func (o Time) ElseZero() (value time.Time)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Time) Get

func (o Time) Get() (value time.Time, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Time) If

func (o Time) If(f func(value time.Time))

If calls the function if there is a value wrapped by this optional.

func (Time) IsPresent

func (o Time) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Time) MarshalJSON

func (o Time) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Time) MarshalXML

func (o Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Time) String

func (o Time) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Time) UnmarshalJSON

func (o *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Time) UnmarshalXML

func (o *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Uint

type Uint optionalUint

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyUint

func EmptyUint() Uint

Empty returns an empty optional.

func OfUint

func OfUint(value uint) Uint

Of wraps the value in an optional.

func OfUintPtr

func OfUintPtr(ptr *uint) Uint

func (Uint) Else

func (o Uint) Else(elseValue uint) (value uint)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Uint) ElseFunc

func (o Uint) ElseFunc(f func() uint) (value uint)

func (Uint) ElseZero

func (o Uint) ElseZero() (value uint)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Uint) Get

func (o Uint) Get() (value uint, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Uint) If

func (o Uint) If(f func(value uint))

If calls the function if there is a value wrapped by this optional.

func (Uint) IsPresent

func (o Uint) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Uint) MarshalJSON

func (o Uint) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint) MarshalXML

func (o Uint) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint) String

func (o Uint) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Uint) UnmarshalJSON

func (o *Uint) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Uint) UnmarshalXML

func (o *Uint) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Uint16

type Uint16 optionalUint16

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyUint16

func EmptyUint16() Uint16

Empty returns an empty optional.

func OfUint16

func OfUint16(value uint16) Uint16

Of wraps the value in an optional.

func OfUint16Ptr

func OfUint16Ptr(ptr *uint16) Uint16

func (Uint16) Else

func (o Uint16) Else(elseValue uint16) (value uint16)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Uint16) ElseFunc

func (o Uint16) ElseFunc(f func() uint16) (value uint16)

func (Uint16) ElseZero

func (o Uint16) ElseZero() (value uint16)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Uint16) Get

func (o Uint16) Get() (value uint16, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Uint16) If

func (o Uint16) If(f func(value uint16))

If calls the function if there is a value wrapped by this optional.

func (Uint16) IsPresent

func (o Uint16) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Uint16) MarshalJSON

func (o Uint16) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint16) MarshalXML

func (o Uint16) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint16) String

func (o Uint16) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Uint16) UnmarshalJSON

func (o *Uint16) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Uint16) UnmarshalXML

func (o *Uint16) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Uint32

type Uint32 optionalUint32

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyUint32

func EmptyUint32() Uint32

Empty returns an empty optional.

func OfUint32

func OfUint32(value uint32) Uint32

Of wraps the value in an optional.

func OfUint32Ptr

func OfUint32Ptr(ptr *uint32) Uint32

func (Uint32) Else

func (o Uint32) Else(elseValue uint32) (value uint32)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Uint32) ElseFunc

func (o Uint32) ElseFunc(f func() uint32) (value uint32)

func (Uint32) ElseZero

func (o Uint32) ElseZero() (value uint32)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Uint32) Get

func (o Uint32) Get() (value uint32, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Uint32) If

func (o Uint32) If(f func(value uint32))

If calls the function if there is a value wrapped by this optional.

func (Uint32) IsPresent

func (o Uint32) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Uint32) MarshalJSON

func (o Uint32) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint32) MarshalXML

func (o Uint32) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint32) String

func (o Uint32) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Uint32) UnmarshalJSON

func (o *Uint32) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Uint32) UnmarshalXML

func (o *Uint32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Uint64

type Uint64 optionalUint64

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyUint64

func EmptyUint64() Uint64

Empty returns an empty optional.

func OfUint64

func OfUint64(value uint64) Uint64

Of wraps the value in an optional.

func OfUint64Ptr

func OfUint64Ptr(ptr *uint64) Uint64

func (Uint64) Else

func (o Uint64) Else(elseValue uint64) (value uint64)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Uint64) ElseFunc

func (o Uint64) ElseFunc(f func() uint64) (value uint64)

func (Uint64) ElseZero

func (o Uint64) ElseZero() (value uint64)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Uint64) Get

func (o Uint64) Get() (value uint64, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Uint64) If

func (o Uint64) If(f func(value uint64))

If calls the function if there is a value wrapped by this optional.

func (Uint64) IsPresent

func (o Uint64) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Uint64) MarshalJSON

func (o Uint64) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint64) MarshalXML

func (o Uint64) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint64) String

func (o Uint64) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Uint64) UnmarshalJSON

func (o *Uint64) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Uint64) UnmarshalXML

func (o *Uint64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Uint8

type Uint8 optionalUint8

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyUint8

func EmptyUint8() Uint8

Empty returns an empty optional.

func OfUint8

func OfUint8(value uint8) Uint8

Of wraps the value in an optional.

func OfUint8Ptr

func OfUint8Ptr(ptr *uint8) Uint8

func (Uint8) Else

func (o Uint8) Else(elseValue uint8) (value uint8)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Uint8) ElseFunc

func (o Uint8) ElseFunc(f func() uint8) (value uint8)

func (Uint8) ElseZero

func (o Uint8) ElseZero() (value uint8)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Uint8) Get

func (o Uint8) Get() (value uint8, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Uint8) If

func (o Uint8) If(f func(value uint8))

If calls the function if there is a value wrapped by this optional.

func (Uint8) IsPresent

func (o Uint8) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Uint8) MarshalJSON

func (o Uint8) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint8) MarshalXML

func (o Uint8) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uint8) String

func (o Uint8) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Uint8) UnmarshalJSON

func (o *Uint8) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Uint8) UnmarshalXML

func (o *Uint8) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

type Uintptr

type Uintptr optionalUintptr

Optional wraps a value that may or may not be nil. If a value is present, it may be unwrapped to expose the underlying value.

func EmptyUintptr

func EmptyUintptr() Uintptr

Empty returns an empty optional.

func OfUintptr

func OfUintptr(value uintptr) Uintptr

Of wraps the value in an optional.

func OfUintptrPtr

func OfUintptrPtr(ptr *uintptr) Uintptr

func (Uintptr) Else

func (o Uintptr) Else(elseValue uintptr) (value uintptr)

Else returns the value wrapped by this optional, or the value passed in if there is no value wrapped by this optional.

func (Uintptr) ElseFunc

func (o Uintptr) ElseFunc(f func() uintptr) (value uintptr)

func (Uintptr) ElseZero

func (o Uintptr) ElseZero() (value uintptr)

ElseZero returns the value wrapped by this optional, or the zero value of the type wrapped if there is no value wrapped by this optional.

func (Uintptr) Get

func (o Uintptr) Get() (value uintptr, ok bool)

Get returns the value wrapped by this optional, and an ok signal for whether a value was wrapped.

func (Uintptr) If

func (o Uintptr) If(f func(value uintptr))

If calls the function if there is a value wrapped by this optional.

func (Uintptr) IsPresent

func (o Uintptr) IsPresent() bool

IsPresent returns true if there is a value wrapped by this optional.

func (Uintptr) MarshalJSON

func (o Uintptr) MarshalJSON() (data []byte, err error)

MarshalJSON marshals the value being wrapped to JSON. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uintptr) MarshalXML

func (o Uintptr) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the value being wrapped to XML. If there is no vale being wrapped, the zero value of its type is marshaled.

func (Uintptr) String

func (o Uintptr) String() string

String returns the string representation of the wrapped value, or the string representation of the zero value of the type wrapped if there is no value wrapped by this optional.

func (*Uintptr) UnmarshalJSON

func (o *Uintptr) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into a value wrapped by this optional.

func (*Uintptr) UnmarshalXML

func (o *Uintptr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the XML into a value wrapped by this optional.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL