Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Oct 20, 2023
1 parent 10e3598 commit 24fd8bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/bencode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ impl fmt::Debug for BencodeValue {
}

pub fn parse_bencoded(bencoded: Vec<u8>) -> (Option<BencodeValue>, Vec<u8>) {
let next = bencoded.iter().next().unwrap();
let next = bencoded.first().unwrap();
match *next as char {
c if c.is_ascii_digit() => parse_string(bencoded),
c if c == 'i' => parse_int(bencoded),
c if c == 'l' => parse_list(bencoded),
c if c == 'd' => parse_dict(bencoded),
_ => {
eprintln!("unexpected character `{}`", *next as char);
return (None, bencoded);
(None, bencoded)
}
}
}
Expand Down Expand Up @@ -180,6 +180,7 @@ pub fn parse_dict(bencoded: Vec<u8>) -> (Option<BencodeValue>, Vec<u8>) {
)
}

#[cfg(test)]
mod test {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
if !left.is_empty() {
panic!("trailing bencoded data: {}", String::from_utf8(left).unwrap());
}
println!("{:#?}", metadata);
println!("{metadata:#?}");
}
}

0 comments on commit 24fd8bf

Please sign in to comment.