str

package module
v0.0.0-...-cfa504e Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

str

str: seamlessly work with Strings in Go 🚤

Issues License Go Documentation Go Report PRs Welcome

Quickstart

Unsafe, zero-allocation conversions between string and []byte.

package main

import "github.com/felix-kaestner/str"

func main() {
    json := `{"foo":{"bar":42}}`
    // Shares the same underlying memory
    var buf []byte = str.UnsafeBytes(json)
}

Installation

Install with the go get command:

go get -u github.com/felix-kaestner/str

Released under the Apache 2.0 License.

Documentation

Overview

Package str provides unsafe, zero-allocation conversions between Go's string and []byte types. It is designed for use in performance-sensitive situations where minimizing memory allocations is essential.

Background

Go's standard conversions between string and []byte are are straightforward, but they always allocate new memory and copy data. This ensures immutability and type safety, but can introduce overhead in high-performance code. This package provides unsafe alternatives to these conversions that avoid these allocations, allowing direct access to the underlying data.

Disclaimer

Only use these functions if you fully understand the implications of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnsafeBytes

func UnsafeBytes(s string) []byte

UnsafeBytes returns a byte slice from a string without allocation.

func UnsafeString

func UnsafeString(b []byte) string

UnsafeString returns a string from a byte slice without allocation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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