pub struct DracoError { /* private fields */ }Expand description
Error returned by Draco decoding, encoding, and data model operations.
One pointer wide, in the shape of std::io::Error: the ErrorKind and
the message live behind a single boxed allocation that is only made on the
failure path. This is not a style preference. Almost every decode and encode
function in this crate returns Status, and when the error was an enum
carrying a String inline, Result<(), DracoError> was 32 bytes and needed
dropping: every one of those functions returned through a hidden out-pointer
and every ? expanded to String drop glue. Boxing makes the success case a
null pointer in a register and reduces the drop glue to one shared function.
Measured on the glTF WASM module, that is 2.6 KiB of gzipped code. It is not
what dominates, and this comment says so because the first guess was wrong:
the message text and the format! that builds it are worth 16 KiB in the
same module, and no shape of the error type reaches those.
The kind is matched with kind rather than by pattern, and it
is #[non_exhaustive], so a later release can tell one refusal from another
without a major bump.
use draco_core::{DracoError, ErrorKind};
let error = DracoError::unsupported_feature("multi-pass attribute coding");
assert_eq!(error.kind(), ErrorKind::UnsupportedFeature);
assert_eq!(error.message(), "multi-pass attribute coding");
assert_eq!(
error.to_string(),
"Unsupported feature: multi-pass attribute coding"
);Implementations§
Source§impl DracoError
impl DracoError
Sourcepub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
Builds an error of kind carrying message.
Cold and never inlined so that the allocation is emitted once rather than at each of the several hundred sites that construct an error.
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
The message alone, without the fixed text ErrorKind::as_str adds.
Empty for kinds that carry no detail.
Sourcepub fn general(message: impl Into<String>) -> Self
pub fn general(message: impl Into<String>) -> Self
A generic failure. See ErrorKind::General.
Sourcepub fn io(message: impl Into<String>) -> Self
pub fn io(message: impl Into<String>) -> Self
A file or stream failure. See ErrorKind::Io.
Sourcepub fn invalid_parameter(message: impl Into<String>) -> Self
pub fn invalid_parameter(message: impl Into<String>) -> Self
A rejected caller-provided parameter. See ErrorKind::InvalidParameter.
Sourcepub fn unsupported_version(message: impl Into<String>) -> Self
pub fn unsupported_version(message: impl Into<String>) -> Self
A known but unsupported bitstream version. See ErrorKind::UnsupportedVersion.
Sourcepub fn unknown_version(message: impl Into<String>) -> Self
pub fn unknown_version(message: impl Into<String>) -> Self
An unidentifiable bitstream version. See ErrorKind::UnknownVersion.
Sourcepub fn unsupported_feature(message: impl Into<String>) -> Self
pub fn unsupported_feature(message: impl Into<String>) -> Self
A bitstream feature this crate does not implement. See ErrorKind::UnsupportedFeature.
Sourcepub fn bitstream_version_unsupported() -> Self
pub fn bitstream_version_unsupported() -> Self
A bitstream version outside the supported range.
See ErrorKind::BitstreamVersionUnsupported.
Sourcepub fn buffer(message: impl Into<String>) -> Self
pub fn buffer(message: impl Into<String>) -> Self
A failed buffer read or write. See ErrorKind::Buffer.
Sourcepub fn context(self, context: impl Display) -> Self
pub fn context(self, context: impl Display) -> Self
A decode that asked for more memory than its input could describe.
See ErrorKind::AllocationExceedsInput.
Prefixes this error’s message with context, keeping its kind.
The kind is what a caller matches on, so a layer that adds context has
to carry it through. Rebuilding the error as
general instead flattens every refusal underneath
into one kind – which is how a caller’s own
LimitExceeded ceiling became
indistinguishable from a corrupt file.
pub fn allocation_exceeds_input( requested_bytes: usize, stream_bytes: usize, ) -> Self
Trait Implementations§
Source§impl Clone for DracoError
impl Clone for DracoError
Source§impl Debug for DracoError
Prints the kind and the message rather than the box, so that a {:?} of a
Result reads the way the enum’s did.
impl Debug for DracoError
Prints the kind and the message rather than the box, so that a {:?} of a
Result reads the way the enum’s did.
Source§impl Display for DracoError
impl Display for DracoError
impl Eq for DracoError
Source§impl Error for DracoError
impl Error for DracoError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()