langchain_rust/output_parsers/
simple_parser.rs

1use async_trait::async_trait;
2
3use super::{OutputParser, OutputParserError};
4
5pub struct SimpleParser {
6    trim: bool,
7}
8impl SimpleParser {
9    pub fn new() -> Self {
10        Self { trim: false }
11    }
12    pub fn with_trim(mut self, trim: bool) -> Self {
13        self.trim = trim;
14        self
15    }
16}
17impl Default for SimpleParser {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23#[async_trait]
24impl OutputParser for SimpleParser {
25    async fn parse(&self, output: &str) -> Result<String, OutputParserError> {
26        if self.trim {
27            Ok(output.trim().to_string())
28        } else {
29            Ok(output.to_string())
30        }
31    }
32}