pub enum Data<T> {
Chat(ChatMessageCollection<T>),
Text(T),
}
Expand description
An enum representing either a collection of chat messages or a single text.
Variants§
Implementations§
Source§impl<T> Data<T>
impl<T> Data<T>
pub fn text(text: T) -> Self
Sourcepub fn map<U, F: Fn(&T) -> U>(&self, f: F) -> Data<U>
pub fn map<U, F: Fn(&T) -> U>(&self, f: F) -> Data<U>
Maps the body of the chat messages or the text in the Data
enum using the provided function.
§Arguments
f
- A function that takes a reference to the body of a chat message or the text and returns a value of typeU
.
§Returns
A new Data<U>
with the body of the chat messages or the text mapped by the provided function.
Sourcepub fn try_map<U, E, F: Fn(&T) -> Result<U, E>>(
&self,
f: F,
) -> Result<Data<U>, E>
pub fn try_map<U, E, F: Fn(&T) -> Result<U, E>>( &self, f: F, ) -> Result<Data<U>, E>
Maps the body of the chat messages or the text in the Data
enum using the provided function that might fail.
§Arguments
f
- A function that takes a reference to the body of a chat message or the text and returns aResult<U, E>
value.
§Returns
A Result<Data<U>, E>
with the body of the chat messages or the text mapped by the provided function.
If the provided function returns an error, the error will be propagated in the result.
Sourcepub fn extract_last_body(&self) -> Option<&T>
pub fn extract_last_body(&self) -> Option<&T>
Extracts the body of the last message in the Data, or simply returns the Text if it is a text prompt
Source§impl Data<String>
impl Data<String>
pub fn to_chat(&self) -> ChatMessageCollection<String>
pub fn to_text(&self) -> String
Sourcepub fn combine(&self, other: &Self) -> Self
pub fn combine(&self, other: &Self) -> Self
Combines two Data
values into one.
If both values are Chat
, the two chat collections will be combined.
If one value is Chat
and the other is Text
, the text will be added as a message to the chat collection.
§Arguments
other
- The otherData
value to combine with.