pub fn parse<T: DeserializeOwned>(input: &str) -> Result<T>Expand description
Parses an LLM response into a strongly-typed Rust struct.
This is the main entry point for the library. It combines flexible parsing with smart type coercion to handle messy LLM outputs.
§Examples
use tryparse::parse;
use serde::Deserialize;
#[derive(Deserialize, Debug, PartialEq)]
struct User {
name: String,
age: u32,
}
let response = r#"{"name": "Alice", "age": "30"}"#;
let user: User = parse(response).unwrap();
assert_eq!(user, User { name: "Alice".into(), age: 30 });§Errors
Returns ParseError::NoCandidates if no valid JSON could be extracted.
Returns ParseError::DeserializeFailed if deserialization fails for all candidates.