pub enum MessageBlock {
Text(String),
Code {
code: String,
language: Option<String>,
},
ToolUse {
name: String,
input: Option<String>,
output: Option<String>,
},
Thinking(String),
Error(String),
}Expand description
A block of content within a conversation message.
Messages are composed of one or more blocks, each representing a different type of content (text, code, tool use, etc.).
Variants§
Text(String)
Plain text content.
Code
A code block with optional language identifier.
Fields
ToolUse
A tool/function use block.
Fields
Thinking(String)
A thinking/reasoning block (e.g., chain-of-thought).
Error(String)
An error block.
Implementations§
Source§impl MessageBlock
impl MessageBlock
Sourcepub fn text(content: impl Into<String>) -> Self
pub fn text(content: impl Into<String>) -> Self
Creates a text block.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::text("Hello, world!");
assert!(matches!(block, MessageBlock::Text(ref s) if s == "Hello, world!"));Sourcepub fn code(code: impl Into<String>, language: Option<&str>) -> Self
pub fn code(code: impl Into<String>, language: Option<&str>) -> Self
Creates a code block with a language.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::code("fn main() {}", Some("rust"));
if let MessageBlock::Code { code, language } = &block {
assert_eq!(code, "fn main() {}");
assert_eq!(language.as_deref(), Some("rust"));
}Sourcepub fn tool_use(name: impl Into<String>) -> Self
pub fn tool_use(name: impl Into<String>) -> Self
Creates a tool use block with only a name.
Use with_input and with_output
to attach input and output data via the builder pattern.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::tool_use("search");
if let MessageBlock::ToolUse { name, input, output } = &block {
assert_eq!(name, "search");
assert!(input.is_none());
assert!(output.is_none());
}Sourcepub fn with_input(self, input: impl Into<String>) -> Self
pub fn with_input(self, input: impl Into<String>) -> Self
Sets the input for a tool use block (builder pattern).
Has no effect on non-ToolUse variants.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::tool_use("search")
.with_input("query: rust TUI");
if let MessageBlock::ToolUse { name, input, .. } = &block {
assert_eq!(name, "search");
assert_eq!(input.as_deref(), Some("query: rust TUI"));
}Sourcepub fn with_output(self, output: impl Into<String>) -> Self
pub fn with_output(self, output: impl Into<String>) -> Self
Sets the output for a tool use block (builder pattern).
Has no effect on non-ToolUse variants.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::tool_use("search")
.with_input("query: rust TUI")
.with_output("Found 5 results");
if let MessageBlock::ToolUse { name, input, output } = &block {
assert_eq!(name, "search");
assert_eq!(input.as_deref(), Some("query: rust TUI"));
assert_eq!(output.as_deref(), Some("Found 5 results"));
}Sourcepub fn thinking(content: impl Into<String>) -> Self
pub fn thinking(content: impl Into<String>) -> Self
Creates a thinking block.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::thinking("Let me reason about this...");
assert!(matches!(block, MessageBlock::Thinking(ref s) if s == "Let me reason about this..."));Sourcepub fn error(content: impl Into<String>) -> Self
pub fn error(content: impl Into<String>) -> Self
Creates an error block.
§Example
use envision::component::MessageBlock;
let block = MessageBlock::error("Connection timeout");
assert!(matches!(block, MessageBlock::Error(ref s) if s == "Connection timeout"));Sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Returns true if this is a text block.
§Example
use envision::component::MessageBlock;
assert!(MessageBlock::text("hello").is_text());
assert!(!MessageBlock::thinking("thoughts").is_text());Sourcepub fn is_code(&self) -> bool
pub fn is_code(&self) -> bool
Returns true if this is a code block.
§Example
use envision::component::MessageBlock;
assert!(MessageBlock::code("let x = 1;", Some("rust")).is_code());
assert!(!MessageBlock::text("hello").is_code());Sourcepub fn is_tool_use(&self) -> bool
pub fn is_tool_use(&self) -> bool
Returns true if this is a tool use block.
§Example
use envision::component::MessageBlock;
assert!(MessageBlock::tool_use("search").is_tool_use());
assert!(!MessageBlock::text("hello").is_tool_use());Sourcepub fn is_thinking(&self) -> bool
pub fn is_thinking(&self) -> bool
Returns true if this is a thinking block.
§Example
use envision::component::MessageBlock;
assert!(MessageBlock::thinking("reasoning...").is_thinking());
assert!(!MessageBlock::text("hello").is_thinking());Trait Implementations§
Source§impl Clone for MessageBlock
impl Clone for MessageBlock
Source§fn clone(&self) -> MessageBlock
fn clone(&self) -> MessageBlock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MessageBlock
impl Debug for MessageBlock
Source§impl<'de> Deserialize<'de> for MessageBlock
impl<'de> Deserialize<'de> for MessageBlock
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for MessageBlock
impl PartialEq for MessageBlock
Source§impl Serialize for MessageBlock
impl Serialize for MessageBlock
impl Eq for MessageBlock
impl StructuralPartialEq for MessageBlock
Auto Trait Implementations§
impl Freeze for MessageBlock
impl RefUnwindSafe for MessageBlock
impl Send for MessageBlock
impl Sync for MessageBlock
impl Unpin for MessageBlock
impl UnsafeUnpin for MessageBlock
impl UnwindSafe for MessageBlock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more