unsafe

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 2 Imported by: 14

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(src []byte) (d string)

BytesToString casts src to a string without extra memory allocation. The string returned by this function shares memory with "src".

Example
package main

import (
	"fmt"

	"github.com/grailbio/base/unsafe"
)

func main() {
	fmt.Println(unsafe.BytesToString([]byte{'A', 'b', 'C'}))
}
Output:

AbC

func StringToBytes

func StringToBytes(src string) (d []byte)

StringToBytes casts src to []byte without extra memory allocation. The data returned by this function shares memory with "src".

Example
package main

import (
	"fmt"

	"github.com/grailbio/base/unsafe"
)

func main() {
	fmt.Println(unsafe.StringToBytes("AbC"))
}
Output:

[65 98 67]

Types

This section is empty.

Jump to

Keyboard shortcuts

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