Add >> operator similar to C++; Helps with type inference

This commit is contained in:
Zahary Karadjov 2018-10-16 02:16:34 +03:00
parent 1be7c93963
commit 623a19db8d
2 changed files with 9 additions and 1 deletions

View File

@ -391,6 +391,10 @@ proc toNodes*(self: var Rlp): RlpNode =
template read*(rlp: var Rlp, T: type): auto =
readImpl(rlp, T)
proc `>>`*[T](rlp: var Rlp, location: var T) =
mixin read
location = rlp.read(T)
template readRecordType*(rlp: var Rlp, T: type, wrappedInList: bool): auto =
readImpl(rlp, T, wrappedInList)

View File

@ -105,8 +105,12 @@ test "encode and decode lists":
list.enterList
check list.toString == "Lorem ipsum dolor sit amet"
list.skipElem
check list.toInt(int32) == 6000.int32
list.skipElem
var intVar: int
list >> intVar
check intVar == 6000
check(not list.hasData)
expect Exception: list.skipElem