unsafe

package
v0.15.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: Apache-2.0 Imports: 2 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(b []byte) 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

func WithBytes(s string, fn BytesFn)

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

func WithString(b []byte, fn StringFn)

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 BytesFn

type BytesFn func(ImmutableBytes)

BytesFn processes a 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.

type StringFn

type StringFn func(string)

StringFn processes a byte slice.

Jump to

Keyboard shortcuts

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