method Decoder.readStr
Reads a text.
Example:
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }
data Lower {}
impl Codec<str> for Lower {
static fn encode(x: &str, w: &var Encoder) -> () | EncodeError { w.writeStr(x) }
static fn decode(r: &var Decoder) -> str | DecodeError {
match r.readStr() {
str s => s.lower()
DecodeError e => fail e
}
}
static fn schema() -> Schema => Schema.of("string")
}
data Wrap {
@codec(Lower) name: str
}
fn main() io {
let b = encode(&Wrap{ name: "ABC" })!
print(decode<Wrap>(&b)!.name)
}Output
abc
var fn readStr() -> str | DecodeErrorSince. 1.0.0-beta
Returns
str
Errors
DecodeError@error- `DecodeError.Malformed` when the next value is not a text.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/ser/ser.oxl:1640