fn encode
Encodes x (§9, II.2). Compile error if T is not Serializable, or contains secret<T> and fmt is statically
Format.Json ([С §9.3]).
Example:
use std.ser { encode, decode }
fn main() io {
let b = encode(&42)!
let back: i32 = decode(&b)!
print("{back}")
}Output
42
@intrinsic("ser.encode") pub(api) fn encode<T: Serializable>(x: &T, fmt: Format = Format.Oxl) -> bytes | EncodeErrorSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
x | &T |
fmt | Format = Format.Oxl |
Returns
bytes
Errors
EncodeError@error
Effects
none declared (pure unless the body says otherwise)
Defined in: std/ser/ser.oxl:2289