diff --git a/rlp.nim b/rlp.nim index 5a6e244..930b173 100644 --- a/rlp.nim +++ b/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) diff --git a/tests/test_api_usage.nim b/tests/test_api_usage.nim index dd25330..cc8ddc8 100644 --- a/tests/test_api_usage.nim +++ b/tests/test_api_usage.nim @@ -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