[rlp] Add no_std support#167
Conversation
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
dvdplm
left a comment
There was a problem hiding this comment.
In general it looks good – we definitely want to move to the 2018 edition and no_std capability is always welcome. I don't understand why tests&benchmarks need to be no_std though, can you elaborate on that?
| rustc-hex = {version = "2.0", default-features = false } | ||
|
|
||
| [dev-dependencies] | ||
| hex-literal = "0.1" |
There was a problem hiding this comment.
Why prefer rustc-hex to hex-literal?
There was a problem hiding this comment.
I think rustc-hex is enough to encode/decode hex. There is no need to introduce more dependencies, even if it is just dev-dependencies.
There was a problem hiding this comment.
Tests need to be as readable as possible, which is why I thinkhex-literal is better.
There was a problem hiding this comment.
(The new 0.2 of hex-literal is edition compatible too!)
| let mut stream = RlpStream::new_list(1000); | ||
| for _ in 0..1000 { | ||
| stream.append(&U256::from(1)); | ||
| stream.append(&1u64); |
There was a problem hiding this comment.
This changes the amount of data tested, making it impossible to compare tests before/after this change.
In general I'm not sure why the dev dependencies can't depend on primitive-types (or any other code, be it no_std or not). I think the benchmark use the big uint types because it is such a common use case for the crate. What's the point of having the benchmarks be no_std?
There was a problem hiding this comment.
Please use the same data length as before here.
|
@dvdplm Thanks for reviewing my code! I removed the For example, if you define a structure that implements a |
|
I just make tests are |
|
@koushiro no, thank you for contributing! :) So the context for my hesitation about moving the tests is that we've seen several instances of good PRs come in that look perfectly justified and that seem like an easy win and so they are merged but then when someone actually tries to use the new versions in production code, issues pop up. Most of the time it's ergonomic quirks but sometimes in the past we've merged code that turned out to be impossible to use higher up in the stack. I don't actually know what the best way to tackle this is – we can hardly expect all contributor to go through the hassle of upgrading depending crates/projects. The tests you remove here – and I totally understand your reasoning – makes me wonder if we're not removing one barrier to such unfortunate merges: the tests exercise a portion of the stack above itself so we know that part is sort of ok. The obvious objection is that these are unit tests, not integration tests. And of course you and @sorpaas are right: these tests logically belong in Maybe we can meet half-way:
Would that work for you? |
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
| let mut stream = RlpStream::new_list(1000); | ||
| for _ in 0..1000 { | ||
| stream.append(&U256::from(1)); | ||
| stream.append(&1u64); |
There was a problem hiding this comment.
Please use the same data length as before here.
| let rlp = Rlp::new(&data); | ||
| for i in 0..1000 { | ||
| let _: U256 = rlp.val_at(i).unwrap(); | ||
| let _: u64 = rlp.val_at(i).unwrap(); |
There was a problem hiding this comment.
Please use the same data length as before here.
| use byteorder::{ByteOrder, BigEndian}; | ||
| use crate::traits::{Encodable, Decodable}; | ||
|
|
||
| use crate::error::DecoderError; |
There was a problem hiding this comment.
Consider using
use crate::{
…
…
}
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
Let us know when this other PR is ready so we can unblock this one. :) |
|
@koushiro I'll close this for now. Feel free to re-open at any time with the last changes requested. |
Signed-off-by: koushiro koushiro.cqx@gmail.com
What have I changed?
no_stdsupport forrlpcraterlpcrate to 2018 editionprimitive-types(These test cases should be added toprimitive-typesinstead ofrlp)