-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change decoding functions #3
Conversation
} | ||
} | ||
} | ||
pub fn belement_decode(bytes: &[u8], position: &mut usize) -> Result<Bencode, DecodeError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does position
need to be taken by reference?
From what I can see you're using it to move around global state of the position
.
I don't think that's idiomatic Rust.
Primitive types like usize
implement shallow Copy
and are allocated on the stack, so it should be possible to just have straight by-value mut usize
and then return the current position as part of a tuple, without loosing efficiency.
You're fast @synlestidae, awesome work! 👍 Let me know what you think. |
Quite keen on this project so have been working enthusiastically on it haha. I've read your comments, will take them on board. Regarding position as a reference, I did it because it simplifies accounting for the extra element in the return type. But you've convinced me that the return type should have the new position now. |
@synlestidae Haha, nice! Regarding the position pointer, I don't feel super strongly about it (so if you are not 100% convinced, keep the reference),, but I just think that in a good API, it should be clear entirely from the function signature itself, what it does. The position reference has a bit of a magic feel to it. I hope to find time as well, so that if we can do encoding this week, perhaps we can start on the Peer-Wire protocol soon, which is the really interesting part. |
Yes I didn't have time to change the position pointer (which I want to do) but will do so later on today after work. And I'll squash the commits too. |
Change decoding functions to take a length parameter
Thanks! 👍 |
Two key changes here
What do you think? I thought these changes might make implementing the bdict_decode function easier, but I got a little carried away
UPDATE
I implemented the bdict_decode function. It's not tested very well - only has one test. Ready for encoding now!