Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>Rust Loco SnippetsNew to Visual Studio Code? Get it now.
Rust Loco Snippets

Rust Loco Snippets

Snippington

| (0) | Free
Comprehensive code snippets for the Rust Loco framework — from basic controllers and models to advanced workers, mailers, middleware, authentication, testing, and deployment.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Rust Loco Snippets

Comprehensive Visual Studio Code snippets for the Loco web framework for Rust. 100+ snippets covering everything from basic controllers and models to advanced workers, mailers, middleware, authentication, testing, and deployment.

All snippets use the prefix loco- for quick access.

Usage

Type the prefix (e.g., loco-controller-crud) in a .rs file and select the snippet from IntelliSense suggestions. Tab stops are included for easy customization.

Configuration snippets work in .yaml files, Cargo snippets in .toml files, and deployment snippets in Dockerfile files.


App Setup & Configuration

Prefix Description
loco-import Import Loco prelude
loco-import-full Import Loco prelude with common dependencies
loco-hello-world Complete Hello World controller with route
loco-app-hooks App struct with Hooks trait (app.rs)
loco-app-hooks-full Full App hooks with workers, tasks, after_routes
loco-main-rs Main entry point (main.rs)
loco-mod-controllers Controllers module declaration
loco-mod-models Models module declaration

Controllers

Prefix Description
loco-controller-basic Basic controller with single GET endpoint
loco-controller-get GET handler fetching single record by ID
loco-controller-list GET handler listing all records
loco-controller-create POST handler to create a record
loco-controller-update PUT handler to update a record
loco-controller-delete DELETE handler to remove a record
loco-controller-crud Full CRUD controller with all endpoints
loco-controller-health Health check endpoint with DB ping
loco-controller-pagination-full Paginated list endpoint with metadata
loco-controller-streaming Server-Sent Events (SSE) endpoint
loco-controller-multipart Multipart form file upload handler
loco-controller-versioned Versioned API controller (v1/v2)

Routing

Prefix Description
loco-routes-basic Basic routes function
loco-routes-resource RESTful resource routes
loco-routes-nested Nested/versioned API routes
loco-route-add Add a single route

Models & Entities

Prefix Description
loco-model-entity SeaORM entity model definition
loco-model-entity-with-relations Entity with belongs_to relation
loco-model-impl Model implementation with custom finder
loco-model-validation Model validation with validator crate
loco-hooks-on-model Model lifecycle hooks (before/after save/delete)

Migrations

Prefix Description
loco-migration-create-table Create a new table
loco-migration-add-column Add a column to existing table
loco-migration-create-index Create an index
loco-migration-foreign-key Add a foreign key constraint
loco-migration-seed-raw Migration with raw SQL seed data

Request & Response

Prefix Description
loco-response-json Return JSON response
loco-response-json-value Return JSON with inline value
loco-response-empty Return empty response (204)
loco-response-text Return plain text response
loco-response-html Return HTML response
loco-response-redirect Redirect to a URL
loco-response-custom-status Response with custom status code

Parameters & Extractors

Prefix Description
loco-params-json Extract JSON body
loco-params-path Extract path parameter
loco-params-query Extract query parameters
loco-params-state Extract app context state
loco-params-struct Request parameters struct
loco-params-query-struct Query params struct for pagination
loco-extractor-custom Custom extractor (FromRequestParts)
loco-extractor-from-request Custom extractor with validation (FromRequest)

Views

Prefix Description
loco-view-response View/response struct with From implementation
loco-view-pagination Paginated response wrapper struct

Middleware

Prefix Description
loco-middleware-layer Add middleware layer in after_routes
loco-middleware-cors CORS middleware configuration
loco-middleware-timeout Request timeout middleware
loco-middleware-compression Response compression middleware
loco-middleware-trace Request tracing with custom spans
loco-middleware-rate-limit Rate limiting middleware
loco-middleware-custom Custom middleware function
loco-middleware-from-fn-state Custom middleware with app state
loco-middleware-request-id Request ID propagation
loco-middleware-sensitive-headers Mark headers as sensitive
loco-middleware-catch-panic Catch panic middleware

Authentication & Authorization

Prefix Description
loco-auth-jwt-middleware JWT-authenticated endpoint handler
loco-auth-api-token API token authenticated handler
loco-auth-login Login endpoint with JWT generation
loco-auth-register User registration endpoint
loco-auth-forgot-password Forgot password endpoint
loco-auth-routes Authentication routes

Database Queries

Prefix Description
loco-db-find-all Find all records
loco-db-find-by-id Find a record by ID
loco-db-find-by-column Find by column value
loco-db-insert Insert a new record
loco-db-update Update an existing record
loco-db-delete Delete a record by ID
loco-db-paginate Paginated query
loco-db-filter-multiple Query with multiple optional filters
loco-db-transaction Database transaction with commit
loco-db-raw-query Raw SQL query with SeaORM
loco-db-join Query with related entities (JOIN)
loco-db-select-columns Select specific columns only

Tasks

Prefix Description
loco-task-basic Basic task definition
loco-task-seed Database seeding task
loco-task-cleanup Cleanup task for old records

Workers (Background Jobs)

Prefix Description
loco-worker-basic Background worker definition
loco-worker-enqueue Enqueue a background job
loco-worker-email Email sending worker
loco-worker-retry Worker with retry logic

Mailers

Prefix Description
loco-mailer-basic Basic mailer function
loco-mailer-with-worker Mailer with background worker
loco-mailer-template-html Mailer HTML template

Scheduler

Prefix Description
loco-scheduler-basic Basic scheduler job (task)
loco-scheduler-shell Scheduler job (shell command)

Storage

Prefix Description
loco-storage-upload File upload handler
loco-storage-download File download handler
loco-storage-init Initialize storage driver

Cache

Prefix Description
loco-cache-get-set Cache get/set pattern
loco-cache-invalidate Cache invalidation

WebSocket / Channels

Prefix Description
loco-channels-websocket WebSocket echo handler
loco-channels-broadcast WebSocket with broadcast

Initializers

Prefix Description
loco-initializer Custom initializer hook

Error Handling

Prefix Description
loco-error-custom Custom application error type
loco-error-handler-global Global error handler with custom format

Testing

Prefix Description
loco-test-controller Controller integration test
loco-test-controller-auth Authenticated controller test
loco-test-post-json Test POST with JSON body
loco-test-model Model unit test
loco-test-worker Worker unit test
loco-test-task Task unit test
loco-test-snapshot Snapshot test with insta
loco-test-seed-fixture Test fixture/seed helper

Architecture Patterns

Prefix Description
loco-service-layer Service layer pattern
loco-repository-pattern Repository trait pattern
loco-shared-state Shared global state with RwLock
loco-event-bus In-process event bus
loco-rate-limiter-per-key Per-key sliding window rate limiter
loco-soft-delete Soft delete pattern

Advanced

Prefix Description
loco-tracing-structured Structured tracing instrumentation
loco-template-tera HTML template rendering with Tera
loco-openapi-annotations OpenAPI annotations with utoipa
loco-openapi-doc OpenAPI document definition
loco-http-client HTTP client for external APIs
loco-graceful-shutdown Graceful shutdown signal handler

Configuration (YAML)

Prefix Description
loco-config-development Development configuration file
loco-config-production Production configuration file
loco-config-test Test environment configuration
loco-config-mailer Mailer SMTP configuration
loco-config-workers Workers/queue configuration
loco-config-storage Storage configuration
loco-config-scheduler Scheduler configuration
loco-config-cache Cache configuration
loco-config-static-assets Static assets serving
loco-config-logger Logger configuration

Cargo.toml

Prefix Description
loco-cargo-deps Core Loco dependencies
loco-cargo-deps-full Full dependencies including testing
loco-cargo-workspace Workspace Cargo.toml
loco-cargo-migration Migration crate Cargo.toml
loco-cargo-profile-release Optimized release profile

DevOps & Deployment

Prefix Description
loco-dockerfile Multi-stage Dockerfile
loco-dockerfile-with-migrations Dockerfile with auto migrations
loco-docker-compose Docker Compose (app + Postgres + Redis)
loco-docker-compose-dev Docker Compose for development
loco-github-actions-ci GitHub Actions CI workflow
loco-makefile Makefile for common tasks

Pre-requisites

cargo install loco
cargo install sea-orm-cli # Only when DB is needed

Create a new Loco project:

loco new
# Select your app type: SaaS, REST API, or Lightweight

Snippet Levels

Beginner — App setup, basic controllers, routes, models, migrations, responses, parameters

Intermediate — Middleware, authentication, database queries, tasks, views, validation

Advanced — Workers, mailers, custom extractors, storage, cache, WebSocket, testing, deployment, architecture patterns, OpenAPI

Contributing

Feel free to suggest more snippets or contribute via GitHub.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft