method Decoder.readBool
Reads a boolean.
Example:
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}")
}Output
true
var fn readBool() -> bool | DecodeErrorSince. 1.0.0-beta
Returns
bool
Errors
DecodeError@error- `DecodeError.Malformed` when the next value is not a boolean.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/ser/ser.oxl:1606