Skip to content

Commit

Permalink
feat: improve rust snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdivad committed Aug 22, 2024
1 parent 0186fe5 commit 6ab688d
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions packages/nvim/config/snippets/rust.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ snippet tests "tests module for unit tests"
use super::*;

#[test]
fn it_works() {
assert_eq!(1, 1, "Pretty sure 1==1")
fn ${1:it_works}() -> Result<()> {
${0}
assert_eq!(1, 1, "Pretty sure 1==1")

Ok(())
}
}

snippet test "a test"
#[test]
fn ${1:it_works}() -> Result<()> {
${0}
assert_eq!(1, 1, "Pretty sure 1==1")

Ok(())
}

snippet dd "derive macro"
#[derive($0)]

Expand Down Expand Up @@ -40,7 +52,7 @@ snippet do:init:log "init logger"
.init();

snippet use:anyhow "use anyhow (result.context('foo'))"
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};

snippet use:default "default use preamble"
use clap::Parser;
Expand Down Expand Up @@ -119,5 +131,36 @@ snippet do:sys "spawn a comamnd (sync)"
${0:Ok(())}
}

snippet do:walk "walk a tree"
// Cargo.toml
// ignore = "0.4"
//
use ignore::{overrides::OverrideBuilder, WalkBuilder};

let mut walker = WalkBuilder::new(&path);
walker.standard_filters(true);

let globs = vec!["*.acl"];
if !globs.is_empty() {
let mut overrides = OverrideBuilder::new(&path);
for glob in globs {
overrides.add(glob)?;
}

walker.overrides(overrides.build()?);
}

for entry in walker.build() {
match entry {
Ok(entry) => {
let path = entry.path();
if path.is_file() {
${0:todo!()}
}
},
Err(err) => return Err(err).context(format!("Error walking: {}", ${1:&path}.to_string_lossy()))
}
}

snippet do:anyhow:err "create an anyhow error"
Err(anyhow!(format!("${0}")));

0 comments on commit 6ab688d

Please sign in to comment.