Skip to content

Instantly share code, notes, and snippets.

@jrfondren
Created April 22, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrfondren/6afb3050343cf1915ebf17ec3b59454c to your computer and use it in GitHub Desktop.
Save jrfondren/6afb3050343cf1915ebf17ec3b59454c to your computer and use it in GitHub Desktop.
distinct seq[byte]
type
Seq32 = distinct seq[byte]
proc `[]=`(arr: var Seq32; i: int; x: byte) =
var s: seq[byte] = cast[seq[byte]](arr)
s[i] = x
proc firsthalf*(arr: var array[64, byte]): Seq32 =
Seq32(arr[0..31])
proc mutatehalf*(arr: var Seq32) =
for i in 0 .. 31:
arr[i] = byte(i)
import seq32
var buf: array[64, byte]
var x = firsthalf(buf)
x.mutatehalf
echo buf # no mutation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment