decode_default

Function decode_default 

Source
pub fn decode_default<T: DeserializeOwned>(input: &str) -> ToonResult<T>
Expand description

Decode with default options (strict mode, type coercion enabled).

Works with any type implementing serde::Deserialize.

ยงExamples

With structs:

use serde::Deserialize;
use toon_format::decode_default;

#[derive(Deserialize)]
struct Person {
    name: String,
    age: u32,
}

let input = "name: Alice\nage: 30";
let person: Person = decode_default(input)?;
assert_eq!(person.name, "Alice");

With JSON values:

use serde_json::{
    json,
    Value,
};
use toon_format::decode_default;

let input = "tags[3]: reading,gaming,coding";
let result: Value = decode_default(input)?;
assert_eq!(result["tags"], json!(["reading", "gaming", "coding"]));