[][src]Trait hyperbole::field::IsoDecode

pub trait IsoDecode {
    type Repr: DeserializeOwned;
    fn from_repr(repr: Self::Repr) -> Self;
}

Types with an alternate representation that is DeserializeOwned.

For hlists, the deserialization format is equivalent to a struct with the same fields:

use hyperbole::{field::IsoDecode, zoom, R};
use serde::Deserialize;

#[derive(Deserialize)]
struct MyRequest {
    a: String,
    b: u32,
    c: f32,
}

let repr = r#"{"a":"hello-worldo","b":32324,"c":345345.34}"#;

let my_req: MyRequest = serde_json::from_str(repr).unwrap();

let my_req_r: R![a: String, b: u32, c: f32] = serde_json::from_str(repr)
    .map(IsoDecode::from_repr)
    .unwrap();

assert_eq!(my_req.a, *zoom![&my_req_r.a]);
assert_eq!(my_req.b, *zoom![&my_req_r.b]);
assert_eq!(my_req.c, *zoom![&my_req_r.c]);

Associated Types

type Repr: DeserializeOwned

The representation.

Loading content...

Required methods

fn from_repr(repr: Self::Repr) -> Self

Convert from the representation.

Loading content...

Implementations on Foreign Types

impl IsoDecode for HNil[src]

type Repr = RNil

impl<T: DeserializeOwned, Tail: IsoDecode> IsoDecode for HCons<T, Tail>[src]

type Repr = RCons<T, Tail::Repr>

Loading content...

Implementors

Loading content...