tile38/vendor/github.com/tidwall/cast
Josh Baker 3b99a6276e grpc support 2016-09-11 21:25:09 -07:00
..
LICENSE grpc support 2016-09-11 21:25:09 -07:00
README.md grpc support 2016-09-11 21:25:09 -07:00
cast.go grpc support 2016-09-11 21:25:09 -07:00
cast_test.go grpc support 2016-09-11 21:25:09 -07:00

README.md

CAST

Travis CI Build Status GoDoc

Quickly convert string <-> []byte without memory reallocations and create mutable string or immutable []byte.

This package is a danger zone and should not be entered without understanding the ground rules.

  1. Converting a string -> []byte will result in an immutable byte slice. Editing will cause a panic.
  2. Converting a []byte -> string will result in a mutable string. Editing the originial bytes will change the string too.

Create immutable []byte:

var s = "Hello Planet"
b := cast.ToBytes(s)
fmt.Printf("%s\n", "J"+string(b[1:]))

// Output:
// Jello Planet

Create mutable string:

var b = []byte("Hello Planet")
s := cast.ToString(b)
b[0] = 'J'
fmt.Printf("%s\n", s)

// Output:
// Jello Planet

Contact

Josh Baker @tidwall

License

CAST source code is available under the MIT License.