enum DecodeError
Why bytes could not be decoded into a value ([С §9.4]).
Example:
use std.ser { decode, fromHex }
data Person {
id: i64
name: str
}
fn main() io {
// 0801: only field 1 (id = 1) is present
let raw = fromHex("0801")!
match decode<Person>(&raw) {
Person p => print("{p.name}")
DecodeError.Missing m => print("missing {m}")
DecodeError.Invalid _ => print("invalid")
DecodeError.Malformed _ => print("malformed")
}
}Вывод
missing Missing(field: "Person.name")
@error pub(api) enum DecodeErrorС версии. 1.0.0-beta
Варианты
Missing(field: str) | A required field is absent; |
Invalid(msg: str) | The value violates an invariant or a refined type, or is out of range for its type. |
Malformed(msg: str) | The input is not a well-formed message of the format. |
Определено в: std/core/types.oxl:752