Skip to main content

decode

Function decode 

Source
pub fn decode<'de, D, T>(decoder: D) -> Result<T, D::Error>
where D: Decoder<'de>, T: FromStr<Err: Display>,
Expand description

Decode a string and parse it through FromStr.

A parse error is reported through the decoder’s context, formatted through its Display implementation.

§Examples

use std::net::Ipv4Addr;

use musli::Decode;

#[derive(Debug, PartialEq, Decode)]
struct Host {
    #[musli(decode_with = musli::display::decode)]
    address: Ipv4Addr,
}

let host: Host = musli::json::from_str(r#"{"address":"127.0.0.1"}"#)?;
assert_eq!(host, Host { address: Ipv4Addr::LOCALHOST });