Rust Workflow Snippets
Practical Rust snippets for the Zed editor focused on common application-development workflows.
The extension provides templates for Tokio, Serde, thiserror, tracing, Clap, testing, error handling, async traits, and common trait implementations.
Basic syntax already covered by rust-analyzer completions and postfix completions is intentionally excluded.
Features
- Functions returning
Resultandanyhow::Result - Tokio runtime, tasks, channels, timers, and graceful shutdown
- Error definitions with
thiserror - Serialization models and attributes with Serde
- Structured logging and instrumentation with
tracing - Common trait implementations
- Async traits
- Clap command-line interfaces
- Cargo feature flags
- Async filesystem operations
- Testing helpers
Installation
From the Zed extension gallery
After the extension is published:
- Open Zed.
- Open the Extensions page.
- Search for
Rust Workflow Snippets. - Click Install.
Development installation
Clone the repository:
git clone https://github.com/Teamofeyy/rust-snippets.git
cd rust-snippetsThen:
- Open Zed.
- Open the Extensions page.
- Click Install Dev Extension.
- Select the cloned repository directory containing
extension.toml.
You can also invoke the following command from the Zed command palette:
zed: install dev extensionUsage
Open a Rust file, enter a snippet prefix, and select the snippet from the completion menu.
For example, enter:
tokio-spawnto produce:
let handle = tokio::spawn(async move {
});Use Tab and Shift+Tab to move between snippet placeholders.
Dependencies
This extension only inserts source code. It does not automatically add dependencies to your Cargo.toml.
Some snippets require one or more of these crates:
[dependencies]
anyhow = "1"
async-trait = "0.1"
clap = { version = "4", features = ["derive", "env"] }
serde = { version = "1", features = ["derive"] }
thiserror = "2"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
[dev-dependencies]
proptest = "1"
tempfile = "3"Only add the dependencies required by the snippets you use.
Available Snippets
Functions and error handling
fn-result— Create a function returningResultpub-fn-result— Create a public function returningResultasync-fn-result— Create an async function returningResultpub-async-fn-result— Create a public async function returningResultfn-anyhow— Create a function returninganyhow::Resultasync-fn-anyhow— Create an async function returninganyhow::Result
Tokio runtime and tasks
tokio-main— Create a Tokio async entry pointtokio-test— Create an asynchronous Tokio testtokio-test-result— Create an asynchronous Tokio test returningResulttokio-spawn— Spawn an asynchronous Tokio tasktokio-spawn-blocking— Run a blocking operation using Tokiotokio-select— Create atokio::select!blocktokio-timeout— Run a future with a timeouttokio-sleep— Sleep asynchronously using Tokiotokio-interval— Create a Tokio interval looptokio-shutdown— Wait for a graceful Ctrl+C shutdown signal
Tokio channels
tokio-mpsc— Create a Tokio MPSC channeltokio-oneshot— Create a Tokio oneshot channeltokio-watch— Create a Tokio watch channel
Tokio filesystem
tokio-read-file— Read an entire file asynchronouslytokio-write-file— Write a file asynchronouslytokio-create-dir— Create a directory and its parent directories asynchronously
Error types
thiserror— Create an error enum usingthiserrorerror-transparent— Create a transparentthiserrorvarianterror-source— Create athiserrorvariant containing a source error
Serde
serde-struct— Create a serializable and deserializable structserde-default-struct— Create a Serde struct implementingDefaultserde-tagged-enum— Create an internally tagged Serde enumserde-rename— Rename a field during serialization and deserializationserde-skip-none— Skip serializing anOptionwhen it isNone
Tracing
tracing-instrument— Instrument a function usingtracingtracing-instrument-all— Instrument a function while skipping all argumentstracing-info— Create a structured info eventtracing-debug— Create a structured debug eventtracing-warn— Create a structured warning eventtracing-error— Create a structured error eventtracing-error-debug— Log an error using bothDisplayandDebug
Trait implementations
impl-display— Implementstd::fmt::Displayimpl-from-str— Implementstd::str::FromStrimpl-try-from— ImplementTryFromimpl-as-ref— ImplementAsRefimpl-default— ImplementDefaultmanuallybuilder-method— Create a consuming builder method
Async traits
async-trait— Create an async trait usingasync-traitimpl-async-trait— Implement an async trait usingasync-trait
Clap
clap-parser— Create a Clap command-line parserclap-subcommand— Create a Clap subcommand enum
Cargo features
cfg-feature— Compile an item only when a Cargo feature is enabledcfg-feature-mod— Declare a module behind a Cargo featurecfg-feature-pub-mod— Declare a public module behind a Cargo feature
Testing
test-result— Create a synchronous test returninganyhow::Resultproptest— Create a property-based test usingproptesttempdir— Create a temporary test directory usingtempfile
Environment variables
env-required— Read a required environment variable
Design
Rust Workflow Snippets focuses on higher-level application patterns rather than basic Rust syntax.
The extension intentionally avoids snippets that duplicate features already provided by rust-analyzer, including:
- Basic functions, structures, enums, and implementation blocks
OptionandResultmatchingif letandlet elsepatterns- Basic loops
Some,Ok, andErrwrappersBox,Rc, andArcwrappers- Basic debug expressions
This keeps the completion menu smaller and reduces conflicts with language-server suggestions.
Attribution
This project is based on Rust Snippets for Zed, originally created by Bobby Mannino.
The original extension provided the initial project structure and basic Rust snippets.
This fork is maintained by Teamofeyy and focuses on practical Rust workflows that are not already covered by rust-analyzer.
The original copyright notice and MIT license have been retained.
Contributing
Contributions are welcome.
When proposing a new snippet, please ensure that it:
- Saves a meaningful amount of repetitive code
- Represents a commonly used Rust workflow
- Does not duplicate an existing rust-analyzer completion
- Uses clear and consistent placeholders
- Has a unique and descriptive prefix
Before submitting a pull request, install the repository as a Zed development extension and test the snippet in a Rust file.
License
This project is distributed under the MIT License. See LICENSE for details.