[][src]Trait hyperbole::field::IsoEncode

pub trait IsoEncode<'a> {
    type Repr: Serialize;
    fn as_repr(&'a self) -> Self::Repr;
}

Types with an alternate representation that is Serialize.

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

use hyperbole::{field::IsoEncode, r};
use serde::Serialize;

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

let my_req = serde_json::to_string(&MyRequest {
    a: "hello-worldo".into(),
    b: 32324,
    c: 345345.34,
})
.unwrap();

let my_req_r = serde_json::to_string(
    &r! {
        a = "hello-worldo".to_string(),
        b = 32324,
        c = 345345.34,
    }
    .as_repr(),
)
.unwrap();

// both of the above serialize to:
let repr = r#"{"a":"hello-worldo","b":32324,"c":345345.34}"#;

assert_eq!(repr, my_req);
assert_eq!(repr, my_req_r);

Associated Types

type Repr: Serialize

The representation.

Loading content...

Required methods

fn as_repr(&'a self) -> Self::Repr

Convert to the representation.

Loading content...

Implementations on Foreign Types

impl<'a> IsoEncode<'a> for HNil[src]

type Repr = RNil

impl<'a, T: Serialize + 'a, Tail: IsoEncode<'a>> IsoEncode<'a> for HCons<T, Tail>[src]

type Repr = RCons<&'a T, Tail::Repr>

Loading content...

Implementors

Loading content...