Documentation ¶
Overview ¶
Package unsafe contains operations that step around the type safety of Go programs.
Package unsafe contains operations that step around the type safety of Go programs.
Index ¶
- func String(b []byte) string
- func WithBytes(s string, fn BytesFn)
- func WithBytesAndArg(s string, arg interface{}, fn BytesAndArgFn)
- func WithString(b []byte, fn StringFn)
- func WithStringAndArg(b []byte, arg interface{}, fn StringAndArgFn)
- type BytesAndArgFn
- type BytesFn
- type ImmutableBytes
- type StringAndArgFn
- type StringFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func String ¶
String returns a string backed by a byte slice, it is the caller's responsibility not to mutate the bytes while using the string returned. It is much safer to use WithString and WithStringAndArg if possible, which is more likely to force use of the result to just a small block of code.
func WithBytes ¶
WithBytes converts a string to a byte slice with zero heap memory allocations, and calls a function to process the byte slice. It is the caller's responsibility to make sure the callback function passed in does not modify the byte slice in any way, and holds no reference to the byte slice after the function returns.
func WithBytesAndArg ¶
func WithBytesAndArg(s string, arg interface{}, fn BytesAndArgFn)
WithBytesAndArg converts a string to a byte slice with zero heap memory allocations, and calls a function to process the byte slice alongside one argument. It is the caller's responsibility to make sure the callback function passed in does not modify the byte slice in any way, and holds no reference to the byte slice after the function returns.
func WithString ¶
WithString converts a byte slice to a string with zero heap memory allocations, and calls a function to process the string. It is the caller's responsibility to make sure it holds no reference to the string after the function returns.
func WithStringAndArg ¶
func WithStringAndArg(b []byte, arg interface{}, fn StringAndArgFn)
WithStringAndArg converts a byte slice to a string with zero heap memory allocations, and calls a function to process the string with one argument. It is the caller's responsibility to make sure it holds no reference to the string after the function returns.
Types ¶
type BytesAndArgFn ¶
type BytesAndArgFn func(ImmutableBytes, interface{})
BytesAndArgFn takes an argument alongside the byte slice.
type ImmutableBytes ¶
type ImmutableBytes []byte
ImmutableBytes represents an immutable byte slice.
func Bytes ¶
func Bytes(s string) ImmutableBytes
Bytes returns the bytes backing a string, it is the caller's responsibility not to mutate the bytes returned. It is much safer to use WithBytes and WithBytesAndArg if possible, which is more likely to force use of the result to just a small block of code.
type StringAndArgFn ¶
type StringAndArgFn func(string, interface{})
StringAndArgFn takes an argument alongside the byte slice.