Skip to content

Commit 9b6ee51

Browse files
committed
Merge pull request honza#339 from dcbishop/patch-1
Add rust.snippets Awesome. Thanks!
2 parents e69e510 + 513fad9 commit 9b6ee51

File tree

1 file changed

+215
-0
lines changed

1 file changed

+215
-0
lines changed

UltiSnips/rust.snippets

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#######################################################################
2+
# Rust Snippets #
3+
#######################################################################
4+
5+
###############
6+
# Functions #
7+
###############
8+
snippet fn "A function, optionally with arguments and return type."
9+
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
10+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
11+
}
12+
endsnippet
13+
14+
snippet test "Test function"
15+
#[test]
16+
fn ${1:test_function_name}() {
17+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
18+
}
19+
endsnippet
20+
21+
snippet new "A new function"
22+
pub fn new(${2}) -> ${1:Name} {
23+
${VISUAL}${0}return $1 { ${3} };
24+
}
25+
endsnippet
26+
27+
snippet main "The main function"
28+
pub fn main() {
29+
${VISUAL}${0}
30+
}
31+
endsnippet
32+
33+
34+
35+
snippet let "A let statement"
36+
let ${1:name}${3} = ${VISUAL}${2};
37+
endsnippet
38+
39+
snippet pln "println!(..)" b
40+
println!("${1}"${2/..*/, /}${2});
41+
endsnippet
42+
43+
44+
45+
snippet ec "extern crate ..." b
46+
extern crate ${1:sync};
47+
endsnippet
48+
49+
snippet ecl "...extern crate log;" b
50+
#![feature(phase)]
51+
#[phase(syntax, link)] extern crate log;
52+
endsnippet
53+
54+
snippet mod "A mod." b
55+
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
56+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
57+
} /* $1 */
58+
endsnippet
59+
60+
snippet crate "Create header information" b
61+
// Crate ID
62+
#![crate_id = "${1:crate_name}#${2:0.0.1}"]
63+
64+
// Additional metadata attributes
65+
#![desc = "${3:Descrption.}"]
66+
#![license = "${4:BSD}"]
67+
#![comment = "${5:Comment.}"]
68+
69+
// Specify the output type
70+
#![crate_type = "${6:lib}"]
71+
endsnippet
72+
73+
snippet allow "#[allow(..)]" b
74+
#[allow(${1:unused_variable})]
75+
endsnippet
76+
77+
snippet feat "#![feature(..)]" b
78+
#![feature(${1:macro_rules})]
79+
endsnippet
80+
81+
82+
##################
83+
# Common types #
84+
##################
85+
snippet opt "Option<..>"
86+
Option<${1:int}>
87+
endsnippet
88+
89+
snippet res "Result<.., ..>"
90+
Result<${1:~str}, ${2:()}>
91+
endsnippet
92+
93+
94+
95+
96+
snippet if "if .. (if)" b
97+
if ${1:/* condition */} {
98+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
99+
}
100+
endsnippet
101+
102+
snippet mat "match"
103+
match ${1} {
104+
${2} => ${3},
105+
}
106+
endsnippet
107+
108+
snippet while "while .. {}" b
109+
while ${1:condition} {
110+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
111+
}
112+
endsnippet
113+
114+
snippet for "for .. in .." b
115+
for ${1:i} in ${2:range(0u, 10)} {
116+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
117+
}
118+
endsnippet
119+
120+
snippet spawn "spawn(proc() { .. });" b
121+
spawn(proc() {
122+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
123+
});
124+
endsnippet
125+
126+
snippet chan "A channel" b
127+
let (${1:tx}, ${2:rx}): (Sender<${3:int}>, Receiver<${4:int}>) = channel();
128+
endsnippet
129+
130+
snippet duplex "Duplex stream" b
131+
let (${1:from_child}, ${2:to_child}) = sync::duplex();
132+
endsnippet
133+
134+
#####################
135+
# TODO commenting #
136+
#####################
137+
snippet todo "A Todo comment"
138+
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
139+
endsnippet
140+
141+
142+
############
143+
# Struct #
144+
############
145+
snippet st "Struct" b
146+
struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
147+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
148+
}
149+
endsnippet
150+
151+
snippet stn "Struct with new constructor." b
152+
pub struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
153+
${3:/* code */}
154+
}
155+
156+
impl $1 {
157+
pub fn new(${2}) -> $1 {
158+
${4}return $1 {
159+
${5}
160+
};
161+
}
162+
}
163+
endsnippet
164+
165+
166+
##########
167+
# Enum #
168+
##########
169+
snippet enum "An enum" b
170+
enum ${1:enum_name} {
171+
${VISUAL}${0},
172+
}
173+
endsnippet
174+
175+
176+
##########
177+
# Impl #
178+
##########
179+
snippet imp "An impl" b
180+
impl ${1:Name} {
181+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
182+
}
183+
endsnippet
184+
185+
snippet drop "Drop implementation" b
186+
impl Drop for ${1:Name} {
187+
fn drop(&mut self) {
188+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
189+
}
190+
}
191+
endsnippet
192+
193+
194+
############
195+
# Traits #
196+
############
197+
snippet trait "Trait block" b
198+
trait ${1:Name} {
199+
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
200+
}
201+
endsnippet
202+
203+
204+
#############
205+
# Statics #
206+
#############
207+
snippet ss "A static string."
208+
static ${1}: &'static str = "${VISUAL}${0}";
209+
endsnippet
210+
211+
snippet stat "A static variable."
212+
static ${1}: ${2:uint} = ${VISUAL}${0};
213+
endsnippet
214+
215+
# vim:ft=snippets:

0 commit comments

Comments
 (0)