irongit

My nvim configuration

239 lines5.9 KBJSON
1{
2 "Big Comment": {
3 "prefix": [
4 "bc",
5 "big_comment"
6 ],
7 "body": [
8 "// ########################################################################## //",
9 "// ${comment}",
10 "// ########################################################################## //"
11 ]
12 },
13 "Anyhow Result": {
14 "prefix": [
15 "template-anyhow_result",
16 "tar"
17 ],
18 "body": [
19 "anyhow::Result<${1:()}>"
20 ]
21 },
22 "Anyhow Macro": {
23 "prefix": [
24 "template-anyhow_macro",
25 "tam"
26 ],
27 "body": [
28 "anyhow::anyhow!(\"${1}\")"
29 ]
30 },
31 "Anyhow Error": {
32 "prefix": [
33 "template-anyhow_error",
34 "tae"
35 ],
36 "description": "anyhow::Error",
37 "body": [
38 "anyhow::Error"
39 ]
40 },
41 "Anyhow With Context": {
42 "prefix": [
43 "wc",
44 "template-with-context",
45 "twc"
46 ],
47 "description": "Add .with_context(|| format!(\"\")?; to function call",
48 "body": [
49 "with_context(|| format!(\"${1:message}\"))?"
50 ]
51 },
52 "Tracing Instrument": {
53 "prefix": [
54 "template-tracing-instrument",
55 "tracing-instrument",
56 "tti"
57 ],
58 "description": "#[tracing::instrument(err, skip_all, fields())]",
59 "body": [
60 "#[tracing::instrument(name=\"${1:name}\", err, skip_all, fields(${2:fields}))]"
61 ]
62 },
63 "Query As Statement": {
64 "prefix": "template-queryas",
65 "description": "Template for sqlx QueryAs statement",
66 "body": [
67 "let ${1:row} = sqlx::query_as::<_, ${2:TheStruct}>(",
68 "r#\"",
69 "${3:statement}",
70 "\"#,",
71 ")",
72 ".${4:fetch_one}(pool)",
73 ".await?;"
74 ]
75 },
76 "Raw String String Literal": {
77 "prefix": [
78 "template-raw-string-literal",
79 "trsl",
80 "rsl"
81 ],
82 "description": "Simple way to make raw string literal",
83 "body": [
84 "r#\"${1:awesome text}\"#"
85 ]
86 },
87 "Raw String String Literal Multiline": {
88 "prefix": [
89 "template-raw-string-literal-multiline",
90 "trsl-multiline",
91 "rsl-multiline"
92 ],
93 "description": "Simple way to make raw string literal",
94 "body": [
95 "r#\"",
96 "${1:far left text}",
97 "\"#"
98 ]
99 },
100 "Once Cell Sync Lazy": {
101 "prefix": [
102 "template-once-cell-sync-lazy"
103 ],
104 "description": "Build a once_cell::sync::Lazy static value",
105 "body": [
106 "static ${1:NAME}: once_cell::sync::Lazy<${2:Type}> = once_cell::sync::Lazy::new(|| {",
107 "\t// ${1}",
108 "\t${3:function}",
109 "});"
110 ]
111 },
112 "Once Cell Sync Lazy Regex": {
113 "prefix": [
114 "template-once-cell-sync-lazy-regex",
115 "lazy-regex"
116 ],
117 "body": [
118 "${1:pub }static ${2:NAME}_REGEX: once_cell::sync::Lazy<regex::Regex> = once_cell::sync::Lazy::new(|| {",
119 "\tregex::Regex::new(r#\"${3:expression}\"#).unwrap()",
120 "});"
121 ]
122 },
123 "Once Cell Sync Lazy Selector": {
124 "prefix": [
125 "template-once-cell-sync-lazy-selector"
126 ],
127 "body": [
128 "static ${1:NAME}_SELECTOR: once_cell::sync::Lazy<Selector> = once_cell::sync::Lazy::new(|| {",
129 "\tSelector::parse(\"${2:selector}\").unwrap()",
130 "});"
131 ]
132 },
133 "Tracing Span": {
134 "prefix": [
135 "template-new-span"
136 ],
137 "description": "Creates a span and enters it",
138 "body": [
139 "let span = tracing::span!(tracing::Level::${1:ERROR}, \"${2:name}\");",
140 "let _enter = span.enter();"
141 ]
142 },
143 "Current Span": {
144 "prefix": [
145 "template-current-span"
146 ],
147 "description": "Get the current span",
148 "body": [
149 "let span = tracing::Span::current();"
150 ]
151 },
152 "Impl Display": {
153 "prefix": [
154 "impl-display"
155 ],
156 "description": "Impl std::fmt::Display for a struct",
157 "body": [
158 "impl std::fmt::Display for ${1:struct} {",
159 "\tfn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {",
160 "\t\twrite!(f, \"{}\", ${2:self})",
161 "\t}",
162 "}"
163 ]
164 },
165 "Impl Display for Option Wrapper": {
166 "prefix": [
167 "impl-display-opt"
168 ],
169 "description": "Impl a display for an option wrapper",
170 "body": [
171 "impl std::fmt::Display for ${1:OptWrapper} {",
172 "\tfn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {",
173 "\t\tif let Some(val) = &self.0 {",
174 "\t\t\twrite!(f, \"{}\", val)",
175 "\t\t} else {",
176 "\t\t\twrite!(f, \"${2:None}\")",
177 "\t\t}",
178 "\t}",
179 "}"
180 ]
181 },
182 "Impl FromStr": {
183 "prefix": [
184 "impl-from-str"
185 ],
186 "description": "Impl std::str::FromStr for a struct",
187 "body": [
188 "impl std::str::FromStr for ${1:MyStruct} {",
189 "\ttype Err = anyhow::Error;",
190 "\tfn from_str(s: &str) -> Result<Self, Self::Err> {",
191 "\t\t${2:implementation}",
192 "\t}",
193 "}"
194 ]
195 },
196 "Impl Serialize": {
197 "prefix": [
198 "impl-serialize"
199 ],
200 "description": "scaffold for implementing serde serialize",
201 "body": [
202 "impl serde::Serialize for ${1:MyStruct} {",
203 " fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>",
204 " where",
205 " S: serde::Serializer,",
206 " {",
207 " let mut value = serde_json::json!({",
208 " ${2:json values}",
209 " });",
210 " if let Some(obj) = value.as_object_mut() {",
211 " obj.retain(|_, v| !v.is_null())",
212 " }",
213 " value.serialize(serializer)",
214 " }",
215 "}"
216 ]
217 },
218 "Impl Tabled": {
219 "prefix": [
220 "impl-tabled"
221 ],
222 "description": "Scaffold for implementing tabled",
223 "body": [
224 "impl tabled::Tabled for ${1:MyStruct} {",
225 " const LENGTH: usize = ${2:100};",
226 " fn fields(&self) -> Vec<std::borrow::Cow<'_, str>> {",
227 " into_vec![",
228 " ${3:fields}",
229 " ]",
230 " }",
231 " fn headers() -> Vec<std::borrow::Cow<'static, str>> {",
232 " into_vec![",
233 " ${4:titles}",
234 " ]",
235 " }",
236 "}"
237 ]
238 }
239}