Skip to content
CryoCryo home
Stdlibencoding

error

import std::encoding::error; · source

Types

DecodeError

type struct DecodeError with [Eq, Debug] {
    position: i64;
    kind:     DecodeErrorKind;
}

The error every decoder in std::encoding returns: what was wrong with the input, and the byte offset in the input where the decoder found it. describe is the problem without the position, and Display adds it: invalid character at byte 2.

import std::encoding::error::{ DecodeErrorKind };
import std::encoding::percent::{ PercentEncoding };
import std::fmt;

match (PercentEncoding::decode(Str::new("a%2"))) {
    Result::Ok(text) => { }
    Result::Err(e)   => {
        if (e.kind == DecodeErrorKind::InvalidEscape) { fmt::eprintln(f"{e}"); }   // invalid percent escape at byte 1
    }
}

Properties

PropertyTypeNotes
positioni64The byte offset in the input where decoding failed.
kindDecodeErrorKindWhat was wrong there.

Constructors

static new(kind: DecodeErrorKind, position: i64) -> DecodeError;

An error of kind found at byte position of the input.

Methods

describe(&this) -> Str;

What went wrong, without the position; Display adds it.

Trait implementations

implement trait Error for struct DecodeError
implement trait Display for struct DecodeError

DecodeErrorKind

type enum DecodeErrorKind with [Eq, Debug] {
    InvalidCharacter;
    InvalidLength;
    InvalidPadding;
    InvalidEscape;
    InvalidUtf8;
}

Variants

VariantNotes
InvalidCharacterA byte that is not part of the encoding's alphabet.
InvalidLengthAn input whose length no complete encoding can have.
InvalidPaddingPadding where the encoding allows none, or more of it than it allows.
InvalidEscapeA % that two hexadecimal digits do not follow.
InvalidUtf8Decoded bytes that are not well-formed UTF-8, where text was wanted.