This extension provides a collection of Rust code snippets to help you write Rust code more efficiently in Visual Studio Code. With snippets for functions, structs, enums, and more, rust-snippet is designed to boost your productivity and streamline your Rust development.
Basic snippets
fn: Create a basic function
struct: Define a basic struct
enum: Define a basic enum
match: Basic match statement
err: Handle errors with match
if: Basic if-else statement
for: For loop
while: While loop
fn-lifetime: Function with lifetime annotation
let: Immutable variable
let-mut: Mutable variable
vec: Vector initialization
hashmap: HashMap initialization
tuple: Tuple initialization
array: Basic array initialization
macro: Define a basic macro
struct-method: Add a method to a struct
enum-method: Add a method to an enum
trait: Define a trait
impl-trait: Implement a trait for a type
use: Use an external crate or module
doc: Add a documentation comment
test: Create a basic unit test
bench: Create a basic benchmark test
async-fn: Define an async function
await: Await an async expression
option: Handle an Option value
result: Handle a Result value
vec-push: Push a value to a vector
vec-iter: Iterate over a vector
closure: Define a basic closure
iter: Basic iterator usage
trait-call: Call a method defined in a trait
assert: Assert equality in tests
dbg: Print debug information
print: Print a message to the console
dbg-fmt: Debug print with formatting
read-file: Read a file and return its content
write-file: Write content to a file
http-request: Basic HTTP GET request using reqwest
mutex: Create a basic Mutex
Rust Error Handling Snippets
Basic Error Handling: Handle errors with match
Result to Option Conversion: Convert Result to Option
Option to Result Conversion: Convert Option to Result with an error
Propagate Error with ? Operator: Propagate errors using the ? operator
Error Handling with Custom Error Type: Define and use a custom error type
Error Handling with Closure: Handle errors using a closure
Error Handling with If Let: Handle errors with if let
Match with Error Handling and Return: Match with error handling and return
Unwrap with Default Value: Unwrap an Option with a default value
Handle Result with Match and Logging: Handle Result with match and logging
Handle Multiple Errors: Handle different kinds of errors
Early Return on Error: Early return on error
Error Handling with Optional Chaining: Handle errors with optional chaining
Handle Error with Result and Logging: Handle Result with logging
Handle Error with Default Value: Handle Result with a default value on error
Custom Error with Context: Handle errors with custom error context
Error Handling with Result and Optional Chaining: Handle Result with optional chaining and error logging
Handle Error in Async Context: Handle errors in an async function
Error Handling with Match and Option: Handle Option with match
Error Handling with Result and Option Chaining: Handle Result with Option chaining
Handle Error with Result and Option Chaining: Handle Result with Option chaining and error logging
Error Handling with Result and Default Value: Handle Result with a default value on error
Error Handling with Match and Return: Handle Result with match and early return
Error Handling in Async Context: Handle errors in an async context
Handling Error with Option and Result: Handle Option with Result
Handling Result with Error and Default Value: Handle Result with error and default value
Error Handling with If Let and Result: Handle Result with if let
Error Handling with Custom Error Type and Result: Define and use a custom error type with Result
Tip: Check out the animation below to see how quickly you can insert snippets into your code!
Requirements
To use this extension, you need:
Visual Studio Code: The extension is compatible with VS Code versions 1.56.0 and above.
Rust Language Support: Ensure you have Rust installed and set up in your development environment.
Working with Markdown
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
Split the editor (Cmd+\ on macOS or Ctrl+\ on Windows and Linux).
Toggle preview (Shift+Cmd+V on macOS or Shift+Ctrl+V on Windows and Linux).
Press Ctrl+Space (Windows, Linux, macOS) to see a list of Markdown snippets.