method Repr.fromRepr
The value from its representation; called when the type is decoded.
Example:
use std.ser { Repr, DecodeError }
@repr(u8)
data Percent { n: u8 }
impl Repr<u8> for Percent {
fn toRepr() -> u8 => n
static fn fromRepr(v: u8) -> Percent | DecodeError {
if v > 100 { fail DecodeError.Invalid(msg: "over 100") }
Percent{ n: v }
}
}
fn main() io {
match Percent.fromRepr(250) {
Percent p => print("{p.n}")
DecodeError _ => print("rejected")
}
}Output
rejected
static fn fromRepr(v: W) -> Self | DecodeErrorSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
v | W |
Returns
Self
Errors
DecodeError@error- `DecodeError` (usually `Invalid`) when `v` is not a valid representation; decoding then fails with it.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/ser/ser.oxl:213