Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ serde_with = { version = "3.1.0", optional = true }
time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] }
bitvec = "1.0.1"
serde_path_to_error = { version = "0.1.16", optional = true }
simdutf8 = "0.1.5"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
js-sys = "0.3"
Expand Down
6 changes: 2 additions & 4 deletions src/raw/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::Utf8Error;

use crate::spec::ElementType;

/// An error that occurs when attempting to parse raw BSON bytes.
Expand Down Expand Up @@ -44,7 +42,7 @@ pub enum ErrorKind {
MalformedValue { message: String },

/// Improper UTF-8 bytes were found when proper UTF-8 was expected.
Utf8EncodingError(Utf8Error),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error value provided by simdutf8::basic::from_utf8 is zero-sized (because it omits tracking error location in favor of speed) so I didn't see much reason to capture it here; this also means we're not exposing a 0.x crate type in our public API.

Utf8EncodingError,
}

impl std::fmt::Display for Error {
Expand All @@ -60,7 +58,7 @@ impl std::fmt::Display for Error {
ErrorKind::MalformedValue { message } => {
write!(f, "{}malformed value: {:?}", prefix, message)
}
ErrorKind::Utf8EncodingError(e) => write!(f, "{}utf-8 encoding error: {}", prefix, e),
ErrorKind::Utf8EncodingError => write!(f, "{}utf-8 encoding error", prefix),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn read_lenencode(buf: &[u8]) -> Result<&str> {
}

fn try_to_str(data: &[u8]) -> Result<&str> {
std::str::from_utf8(data).map_err(|e| Error::new(ErrorKind::Utf8EncodingError(e)))
simdutf8::basic::from_utf8(data).map_err(|_| Error::new(ErrorKind::Utf8EncodingError))
}

fn usize_try_from_i32(i: i32) -> Result<usize> {
Expand Down