Skip to main content

DracoError

Struct DracoError 

Source
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

Source

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.

Source

pub fn kind(&self) -> ErrorKind

What was refused. See ErrorKind.

Source

pub fn message(&self) -> &str

The message alone, without the fixed text ErrorKind::as_str adds.

Empty for kinds that carry no detail.

Source

pub fn general(message: impl Into<String>) -> Self

A generic failure. See ErrorKind::General.

Source

pub fn io(message: impl Into<String>) -> Self

A file or stream failure. See ErrorKind::Io.

Source

pub fn invalid_parameter(message: impl Into<String>) -> Self

A rejected caller-provided parameter. See ErrorKind::InvalidParameter.

Source

pub fn unsupported_version(message: impl Into<String>) -> Self

A known but unsupported bitstream version. See ErrorKind::UnsupportedVersion.

Source

pub fn unknown_version(message: impl Into<String>) -> Self

An unidentifiable bitstream version. See ErrorKind::UnknownVersion.

Source

pub fn unsupported_feature(message: impl Into<String>) -> Self

A bitstream feature this crate does not implement. See ErrorKind::UnsupportedFeature.

Source

pub fn bitstream_version_unsupported() -> Self

A bitstream version outside the supported range. See ErrorKind::BitstreamVersionUnsupported.

Source

pub fn buffer(message: impl Into<String>) -> Self

A failed buffer read or write. See ErrorKind::Buffer.

Source

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.

Source

pub fn allocation_exceeds_input( requested_bytes: usize, stream_bytes: usize, ) -> Self

Trait Implementations§

Source§

impl Clone for DracoError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DracoError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DracoError

Source§

impl Error for DracoError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<()> for DracoError

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for DracoError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DracoError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.