pub struct ToolPattern { /* private fields */ }Expand description
A tool permission pattern, ready to be emitted in a comma-joined
--allowed-tools / --disallowed-tools value.
See the module docs for the accepted shapes.
Implementations§
Source§impl ToolPattern
impl ToolPattern
Sourcepub fn tool(name: impl Into<String>) -> Self
pub fn tool(name: impl Into<String>) -> Self
A bare tool name, e.g. ToolPattern::tool("Bash") -> Bash.
No validation beyond trimming whitespace; the CLI is the source of truth for which tool names exist.
Sourcepub fn tool_with_args(name: impl Into<String>, args: impl Into<String>) -> Self
pub fn tool_with_args(name: impl Into<String>, args: impl Into<String>) -> Self
A tool with an argument glob, rendered Name(args).
assert_eq!(
ToolPattern::tool_with_args("Bash", "git log:*").as_str(),
"Bash(git log:*)"
);Sourcepub fn all(name: impl Into<String>) -> Self
pub fn all(name: impl Into<String>) -> Self
Shorthand for ToolPattern::tool_with_args with * as the
argument pattern – “any args to this tool.”
assert_eq!(ToolPattern::all("Write").as_str(), "Write(*)");Sourcepub fn mcp(server: impl Into<String>, tool: impl Into<String>) -> Self
pub fn mcp(server: impl Into<String>, tool: impl Into<String>) -> Self
An MCP pattern: mcp__{server}__{tool}. Pass "*" as the tool
to match any tool from the server.
assert_eq!(
ToolPattern::mcp("my-server", "do_thing").as_str(),
"mcp__my-server__do_thing"
);
assert_eq!(
ToolPattern::mcp("my-server", "*").as_str(),
"mcp__my-server__*"
);Sourcepub fn parse(s: impl AsRef<str>) -> Result<Self, PatternError>
pub fn parse(s: impl AsRef<str>) -> Result<Self, PatternError>
Parse and validate a raw CLI-format pattern string.
Validation is shape-level only (non-empty, balanced parens, no comma or control chars). Tool names are not checked against any allowlist because the CLI’s tool inventory evolves independently.
Trait Implementations§
Source§impl AsRef<str> for ToolPattern
impl AsRef<str> for ToolPattern
Source§impl Clone for ToolPattern
impl Clone for ToolPattern
Source§fn clone(&self) -> ToolPattern
fn clone(&self) -> ToolPattern
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more