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 MessageOrText
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 MessageOrText<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.
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.