Skip to main content
Glama
match-expressions-match.md1.27 kB
## Match Expressions: `{#match}` Use `match` for exhaustive pattern matching: Rust ``` enum Visibility { Public, Private, Protected } let visibility = Visibility::Public; let code = ts_template! {     {#match visibility}         {:case Visibility::Public}             public         {:case Visibility::Private}             private         {:case Visibility::Protected}             protected     {/match}     field: string; }; ``` **Generates:** TypeScript ``` public field: string; ``` ### Match with Value Extraction Rust ``` let result: Result<i32, &str> = Ok(42); let code = ts_template! {     const value = {#match result}         {:case Ok(val)}             @{val}         {:case Err(msg)}             throw new Error("@{msg}")     {/match}; }; ``` ### Match with Wildcard Rust ``` let count = 5; let code = ts_template! {     {#match count}         {:case 0}             console.log("none");         {:case 1}             console.log("one");         {:case _}             console.log("many");     {/match} }; ```

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/macroforge-ts/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server