assign2: string support (#81)

This commit is contained in:
Jacek Sieka 2021-04-16 15:23:36 +02:00 committed by GitHub
parent 7d2790fdf4
commit 7fb220d1e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -32,6 +32,10 @@ func assign*[T](tgt: var seq[T], src: openArray[T]) =
tgt.setLen(src.len)
assignImpl(tgt.toOpenArray(0, tgt.high), src)
func assign*(tgt: var string, src: string) =
tgt.setLen(src.len)
assignImpl(tgt.toOpenArrayByte(0, tgt.high), src.toOpenArrayByte(0, tgt.high))
macro unsupported(T: typed): untyped =
error "Assignment of the type " & humaneTypeName(T) & " is not supported"

View File

@ -9,6 +9,7 @@ suite "assign2":
a = 5
b = [2, 3]
c = @[5, 6]
d = "hello"
assign(c, b)
check: c == b
@ -21,6 +22,9 @@ suite "assign2":
assign(c.toOpenArray(0, 1), [2, 2])
check: c == [2, 2]
assign(d, "there!")
check: d == "there!"
var
dis = X(53)