unsafex

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnsafeBytes

func UnsafeBytes(s string) []byte

UnsafeBytes converts a string to a byte slice without copying the underlying data. It creates a new byte slice header pointing to the string's data memory address. WARNING: If the string data is allocated in read-only memory, modifying the returned byte slice will cause a panic.

func UnsafeString

func UnsafeString(bs []byte) string

UnsafeString converts a byte slice to a string without copying the underlying data. It converts the byte slice header directly to a string header.

type SliceHeader struct {
	Data uintptr
	Len  int
	Cap  int
}

type StringHeader struct {
	Data uintptr
	Len  int
}

This works because the memory layouts are similar - the byte slice header can be directly cast to a string header (ignoring the Cap field).

Types

This section is empty.

Jump to

Keyboard shortcuts

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