Skip to main content

ToolEnum

Trait ToolEnum 

Source
pub trait ToolEnum: Sized + Copy {
    // Required methods
    fn type_name() -> &'static str;
    fn from_i32(v: i32) -> Option<Self>;
    fn from_str(s: &str) -> Option<Self>;
    fn as_i32(self) -> i32;
    fn all_int_values() -> Vec<i32>;
    fn all_string_values() -> Vec<&'static str>;
}
Expand description

v1.4.84 §5 B2: 统一 MCP tool enum 接口,让 deser_int_or_enum_str 可泛型化。

Required Methods§

Source

fn type_name() -> &'static str

用于 error message 的人类可读类型名(如 "market" / "order_type"

Source

fn from_i32(v: i32) -> Option<Self>

按 proto int 值查 enum variant;未定义 → None

Source

fn from_str(s: &str) -> Option<Self>

按 string 名 / 别名查 enum variant;未定义 → None

实装应 trim + 大小写灵活匹配(canonical 名 + 常见 alias)

Source

fn as_i32(self) -> i32

返 proto int 值(用于 serialize / handler 下游)

Source

fn all_int_values() -> Vec<i32>

列举所有合法 int 值(用于 error message)

Source

fn all_string_values() -> Vec<&'static str>

列举所有 canonical string 名(用于 error message / schema hints)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§