Skip to main content

MessageBlock

Enum MessageBlock 

Source
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

§code: String

The code content.

§language: Option<String>

Optional programming language for syntax indication.

§

ToolUse

A tool/function use block.

Fields

§name: String

The name of the tool being invoked.

§input: Option<String>

A textual representation of the tool input, if any.

§output: Option<String>

A textual representation of the tool output, if any.

§

Thinking(String)

A thinking/reasoning block (e.g., chain-of-thought).

§

Error(String)

An error block.

Implementations§

Source§

impl MessageBlock

Source

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!"));
Source

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"));
}
Source

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());
}
Source

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"));
}
Source

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"));
}
Source

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..."));
Source

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"));
Source

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());
Source

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());
Source

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());
Source

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());
Source

pub fn is_error(&self) -> bool

Returns true if this is an error block.

§Example
use envision::component::MessageBlock;

assert!(MessageBlock::error("timeout").is_error());
assert!(!MessageBlock::text("hello").is_error());

Trait Implementations§

Source§

impl Clone for MessageBlock

Source§

fn clone(&self) -> MessageBlock

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for MessageBlock

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for MessageBlock

Source§

fn eq(&self, other: &MessageBlock) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MessageBlock

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for MessageBlock

Source§

impl StructuralPartialEq for MessageBlock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,