How to use dependencies in Rust Play online

Hi, I have two questions

I want to run code temporarly on playground () , but that code involve some depedencies like RlpStream etc... so can i run that code without doing any extra work .. like making project, giving cargo.toml file, and then write some dependencies , and then compile/run...

fn main() {

let mut rlp = RlpStream::new_list(4);
rlp.append(&DI);
rlp.append(&epdt);

}
  • Detail of rlp.drain()
    I want to know the details of drain function on rlp.. As i am not a expert, so please explain with example. I shall be very thankful to you.
1 Like

Something that I have wondered myself but have never put the effort to figure it out :confused:

Rust Playground has the most popular crates available. You can use them like if they are already in your dependencies (example). It's not possible to import arbitrary dependencies, though.

Only the top 100 to be exact.

after the stream has finished you can "drain" the inner buffer and return the contents as a ElasticArray1024 although rlp.out() seems like the encouraged way from the docs

let mut stream = RlpStream::new_list(2);
stream.append(&"cat");
assert_eq!(stream.is_finished(), false);
stream.append(&"dog");
assert_eq!(stream.is_finished(), true);
let out = stream.out();
assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);

thanks, but how could i run your in playground.... ?

thanks for your reply.. so RlpStream is not available in playground...??

so RlpStream is included or not ?

in our rlp list there are two items i.e. cat and dog, then what are these values , 0xc8, 0x83 and then again 0x83 ???? i am confused ... would you elaborate further about these values ... why not it would be assert_eq!(out, vec![ b'c', b'a', b't', b'd', b'o', b'g']); or why not it would be assert_eq!(out, vec![ b"cat", b"dog"']);

The complete list of available crates can be seen here.

1 Like

Thanks @alice ... but I think any external crate should be supported ...
Could you explain my other queries.... I shall be very thankful to you....

They are control characters 0x83 looks like a separation character. I'm not sure about the other one, looking through the code my guess is its the length.

There are 30,547 crates that have to be in some way compiled and stored, personally I'd want to avoid paying for all that storage space.

2 Likes

then what about the following code. .. here are three hex number in the starting. ..
main () {
/// let mut stream = RlpStream::new_list(2);
/// stream.begin_list(2).append(&"cat").append(&"dog");
/// stream.append(&"");
/// let out = stream.out();
/// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]);
/// }
0xca and c8 are for?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.