Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostie314159 committed Dec 20, 2023
1 parent 1685be1 commit 1307825
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,17 @@ impl<'a> TryFromCtx<'a, StrCtx> for &'a str {
fn try_from_ctx(src: &'a [u8], ctx: StrCtx) -> Result<(Self, usize), Self::Error> {
let len = match ctx {
StrCtx::Length(len) => len,
StrCtx::Delimiter(delimiter) => match src.iter().copied().position(|c| c == delimiter) {
Some(str_len) => str_len,
None => return Err(error::Error::BadInput { size: 0, msg: "No delimiter was found." })
},
StrCtx::Delimiter(delimiter) => {
match src.iter().copied().position(|c| c == delimiter) {
Some(str_len) => str_len,
None => {
return Err(error::Error::BadInput {
size: 0,
msg: "No delimiter was found.",
})
}
}
}
StrCtx::DelimiterUntil(delimiter, len) => {
if len > src.len() {
return Err(error::Error::TooBig {
Expand All @@ -679,7 +686,12 @@ impl<'a> TryFromCtx<'a, StrCtx> for &'a str {
};
match src.iter().copied().position(|c| c == delimiter) {
Some(str_len) => str_len.min(len),
None => return Err(error::Error::BadInput { size: 0, msg: "No delimiter was found." })
None => {
return Err(error::Error::BadInput {
size: 0,
msg: "No delimiter was found.",
})
}
}
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ mod tests {
.pread_with::<&str>(0, StrCtx::Delimiter(NULL))
.unwrap();
assert_eq!(more, "more");
let result = bytes
.pread_with::<&str>(more.len() + 1, StrCtx::Delimiter(NULL));
let result = bytes.pread_with::<&str>(more.len() + 1, StrCtx::Delimiter(NULL));
assert!(result.is_err());
}

Expand Down

0 comments on commit 1307825

Please sign in to comment.