aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-snippets/UltiSnips/rust.snippets
blob: 40e760557ff5ffaf97a5ae6713dcba764a8bedce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#######################################################################
#                            Rust Snippets                            #
#######################################################################

priority -50

snippet let "let variable declaration" b
let ${1:name}${2:: ${3:type}} = ${4};
endsnippet

snippet letm "let mut variable declaration" b
let mut ${1:name}${2:: ${3:type}} = ${4};
endsnippet

snippet fn "A function, optionally with arguments and return type."
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
	${VISUAL}${0}
}
endsnippet

snippet pfn "A public function, optionally with arguments and return type."
pub fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
	${VISUAL}${0}
}
endsnippet

snippet arg "Function Arguments" i
${1:a}: ${2:T}${3:, arg}
endsnippet

snippet || "Closure, anonymous function (inline)" i
${1:move }|${2}| { $3 }
endsnippet

snippet |} "Closure, anonymous function (block)" i
${1:move }|${2}| {
	$3
}
endsnippet

snippet pri "print!(..)" b
print!("${1}"${2/..*/, /}${2});
endsnippet

snippet pln "println!(..)" b
println!("${1}"${2/..*/, /}${2});
endsnippet

snippet fmt "format!(..)"
format!("${1}"${2/..*/, /}${2});
endsnippet

snippet macro "macro_rules!" b
macro_rules! ${1:name} {
	(${2:matcher}) => (
		${3}
	)
}
endsnippet

snippet mod "A module" b
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
	${VISUAL}${0}
}
endsnippet

snippet for "for .. in .." b
for ${1:i} in ${2} {
	${VISUAL}${0}
}
endsnippet

snippet todo "A Todo comment"
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
endsnippet

snippet st "Struct" b
struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
	${VISUAL}${0}
}
endsnippet

# TODO: fancy dynamic field mirroring like Python slotclass
snippet stn "Struct with new constructor." b
pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
	fd${0}
}

impl $1 {
	pub fn new(${2}) -> $1 {
		$1 { ${3} }
	}
}
endsnippet

snippet fd "Struct field definition" w
${1:name}: ${2:Type},
endsnippet

snippet impl "Struct/Trait implementation" b
impl ${1:Type/Trait}${2: for ${3:Type}} {
	${0}
}
endsnippet

# vim:ft=snippets: