mirror of https://github.com/status-im/nim-rlp.git
Add >> operator similar to C++; Helps with type inference
This commit is contained in:
parent
1be7c93963
commit
623a19db8d
4
rlp.nim
4
rlp.nim
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue