Skip to content

Instantly share code, notes, and snippets.

@jeremychone
Last active February 23, 2023 16:20
Show Gist options
  • Save jeremychone/c92c21d20530ad11ba46c08d8d554e97 to your computer and use it in GitHub Desktop.
Save jeremychone/c92c21d20530ad11ba46c08d8d554e97 to your computer and use it in GitHub Desktop.
{
"pair_lgt": {
"prefix": "<",
"body": [
"<$1>"
],
"description": "<> pair"
},
"pair_bars": {
"prefix": "|",
"body": [
"|$1|"
],
"description": "|| pair"
},
"pair_braces": {
"prefix": "{",
"body": [
"{$1}"
],
"description": "{} pair"
},
"warning-unused": {
"prefix": "allow-unused",
"body": [
"#[allow(unused)]"
],
"description": "allow unused"
},
"ctest": {
"prefix": "ctest",
"body": [
"#[cfg(test)]",
"#[path = \"../_tests/test_${1}\"]",
"mod tests;"
]
},
"use_format": {
"prefix": "uf",
"body": [
"use crate::{s,f};"
],
"description": "use crate::{s,f};"
},
"format": {
"prefix": "f!",
"body": [
"f!(\"${1}\")"
],
"description": "use std::format as f"
},
"default": {
"prefix": "default",
"body": [
"${1:StructName}::default()"
],
"description": "default"
},
"_default": {
"prefix": "..D",
"body": [
"..Default::default()"
],
"description": "default"
},
"impl_default": {
"prefix": "idefault",
"body": [
"impl Default for ${1:name} {",
"\tfn default() -> Self {",
"\t\tSelf {",
"\t\t\t$2",
"\t\t}",
"\t}",
"}"
],
"description": "default implementation"
},
"impl_trait": {
"prefix": "itrait",
"body": [
"impl ${1:Trait} for ${2:Type} {",
"\t$3",
"}"
],
"description": "implement trait"
},
"impl_from": {
"prefix": "ifrom",
"body": [
"impl From<${1:from_type}> for ${2:to_type} {",
"\tfn from(val: ${1}) -> Self {",
"\t\t$3",
"\t}",
"}\n"
],
"description": "default implementation"
},
"option": {
"prefix": "option",
"body": [
"Option<$TM_SELECTED_TEXT>"
],
"description": "Option<>"
},
"box": {
"prefix": "box",
"body": [
"Box::new($1)"
],
"description": "box new"
},
"println": {
"prefix": "jprin",
"body": [ "println!(\"->> $1{$2}\"$3);"],
"description": "println"
},
"for": {
"prefix": "for",
"body": [
"for ${1:elem} in ${2:iter} {",
"\t$0",
"}"
],
"description": "Insert for loop"
},
"if": {
"prefix": "if ",
"body": [
"if ${1:pattern} {",
"\t$TM_SELECTED_TEXT",
"}"
],
"description": "Insert if"
},
"if let": {
"prefix": "if let",
"body": [
"if let ${1:pattern} = ${2:value} {",
"\t$3",
"}"
],
"description": "Insert if to match a specific pattern, useful for enum variants e.g. `Some(inner)`"
},
"macro_rules": {
"prefix": "macro_rules",
"body": [
"macro_rules! $1 {",
"\t($2) => {",
"\t\t$0",
"\t};",
"}"
],
"description": "Insert macro_rules!"
},
"spawn": {
"prefix": [
"thread_spawn",
"spawn"
],
"body": [
"std::thread::spawn(move || {",
"\t$1",
"})"
],
"description": "Wrap code in thread::spawn"
},
"derive": {
"prefix": "derive",
"body": [
"#[derive(${1})]"
],
"description": "#[derive(…)]"
},
"cfg": {
"prefix": "cfg",
"body": [
"#[cfg(${1})]"
],
"description": "#[cfg(…)]"
},
"test": {
"prefix": "test",
"body": [
"#[test]",
"fn ${1:name}() -> Result<(), Box<dyn Error>> {",
" ${2:unimplemented!();}",
" Ok(())",
"}"
],
"description": "#[test]"
},
"comment-module": {
"prefix": "mm",
"body": [
"////////////////////////////////////",
"// ${1:comment}",
"////",
""
],
"description": "Module Comment"
},
"comment-section": {
"prefix": "cc",
"body": [
"// region: --- ${1:Section}",
"$TM_SELECTED_TEXT",
"// endregion: --- ${1:Section}"
],
"description": "Comment Section"
},
"error": {
"prefix": "jerr",
"body": [
"",
"#[derive(thiserror::Error, Debug)]",
"pub enum ${1:CustomError} {",
"\t#[error(\"${3:Error caused by:} {0}\")]",
"\t${2:ErrorOne}(String),",
"",
"\t#[error(transparent)]",
"\tIOError(#[from] std::io::Error),",
"}"
],
"description": "JC - pub enum error with thiserror::Error"
},
"jctest": {
"prefix": "jtest",
"body": [
"#[cfg(test)]",
"mod tests {",
"\tuse super::*;",
"",
"\t#[test]",
"\tfn ${1:test_1}() -> Result<(), Box<dyn std::error::Error>> {",
"\t\tOk(())",
"\t}",
"}"
],
"description": "Tests module"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment