fn decode_view
Checks the structure of buf (missing fields, invariants, malformed input: [С §9.4]) and returns a view of it.
Example:
use std.ser { encode }
use std.core { decode_view }
data Person {
id: i64
name: str
}
fn main() io {
let buf = encode(&Person{ id: 1, name: "bob" })!
match decode_view<Person>(&buf) {
DecodeError _ => print("bad buffer")
_ => print("valid")
}
}Вывод
valid
pub(api) fn decode_view<T: Serializable>(buf: &bytes) -> view T | DecodeErrorСложность. O(size of the buffer): checks the structure once; fields are decoded lazily afterwards.
С версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
buf | &bytes |
Возвращает
view T
Ошибки
DecodeError@error- `DecodeError` (`Missing`, `Invalid`, `Malformed`) when the buffer is not a valid encoded `T`.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/core/view.oxl:111