Michael Bradley, Jr a87f3f85be feat: introduce some changes/additions from test/use-cases branch
But without introducing the use cases tests themselves nor their dependencies
in vendor.
2021-03-12 16:53:08 -06:00

13 lines
337 B
Nim

type
ThreadSafeString* = distinct cstring
proc safe*(input: string): ThreadSafeString =
var res = cast[cstring](allocShared(input.len + 1))
copyMem(res, input.cstring, input.len)
res[input.len] = '\0'
res.ThreadSafeString
proc `$`*(input: ThreadSafeString): string =
result = $(input.cstring)
deallocShared input.cstring