OxL Справочник OxL
РусскийEnglish

method Decoder.readBool

Reads a boolean.

Example:

oxl✓ проверяется в CI
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }

data Flag {}

impl Codec<bool> for Flag {
  static fn encode(x: &bool, w: &var Encoder) -> () | EncodeError { w.writeBool(x) }
  static fn decode(r: &var Decoder) -> bool | DecodeError { r.readBool() }
  static fn schema() -> Schema => Schema.of("bool")
}

data Wrap {
  @codec(Flag) on: bool
}

fn main() io {
  let b = encode(&Wrap{ on: true })!
  print("{decode<Wrap>(&b)!.on}")
}
Вывод
true
var fn readBool() -> bool | DecodeError

С версии. 1.0.0-beta

Возвращает

bool

Ошибки

  • DecodeError @error
  • `DecodeError.Malformed` when the next value is not a boolean.

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/ser/ser.oxl:1606

См. также