pub enum Response {
Single(Item),
Multiline(Vec<Item>),
}Expand description
Represents a parsed inference response
This enum can represent either a single response item or a multi-line list of items. The parser determines the response type based on the formatting pattern found in the input.
Variants§
Single(Item)
Single response item, typically from an inline key-value pair like “KEY: value”
Multiline(Vec<Item>)
Multi-line response containing a list of items with common prefix patterns
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(item: &Item, list: &Vec<Item>) -> Self
pub fn new(item: &Item, list: &Vec<Item>) -> Self
Create a new Response instance from an item and list
This constructor determines whether to create a Single or Multiline response based on the length of the provided list.
§Parameters
item: The first item in the responselist: The complete list of items (including the first item)
§Returns
Response::Single: If the list contains only one itemResponse::Multiline: If the list contains multiple items
Sourcepub fn to_value(&self, typedef: &Typedef) -> Result<Value>
pub fn to_value(&self, typedef: &Typedef) -> Result<Value>
Convert the response to a Value based on type definition
This method performs type-safe conversion of the response content according to the provided type definition. It handles both single and multi-line responses appropriately.
§Parameters
typedef: The type definition specifying expected data type
§Returns
Ok(Value): Successfully converted valueErr: If conversion fails due to type mismatch or parsing errors
§Examples
use aimx::inference::{Response, Item};
use aimx::typedef::Typedef;
use aimx::{Value, Literal, Prefix};
let item = Item::Value(Prefix::None, "42".to_string());
let response = Response::Single(item);
let typedef = Typedef::Number;
match response.to_value(&typedef) {
Ok(Value::Literal(Literal::Number(n))) => assert_eq!(n, 42.0),
_ => panic!("Unexpected result"),
}