vimrc/sources_non_forked/vim-snippets/UltiSnips/rust.snippets

107 lines
2 KiB
Text
Raw Normal View History

2014-04-18 12:58:02 +00:00
#######################################################################
# Rust Snippets #
#######################################################################
2014-07-02 11:18:18 +00:00
priority -50
2015-03-14 20:02:10 +00:00
snippet let "let variable declaration" b
2017-02-11 13:01:38 +00:00
let ${1:name}${2:: ${3:type}} = $4;
2015-03-14 20:02:10 +00:00
endsnippet
snippet letm "let mut variable declaration" b
2017-02-11 13:01:38 +00:00
let mut ${1:name}${2:: ${3:type}} = $4;
2015-03-14 20:02:10 +00:00
endsnippet
snippet fn "A function, optionally with arguments and return type."
2017-02-11 13:01:38 +00:00
fn ${1:function_name}($2)${3/..*/ -> /}$3 {
${VISUAL}$0
2014-04-18 12:58:02 +00:00
}
endsnippet
2015-12-08 13:20:04 +00:00
snippet pfn "A public function, optionally with arguments and return type."
2017-02-11 13:01:38 +00:00
pub fn ${1:function_name}($2)${3/..*/ -> /}$3 {
${VISUAL}$0
2015-12-08 13:20:04 +00:00
}
endsnippet
2015-03-14 20:02:10 +00:00
snippet arg "Function Arguments" i
${1:a}: ${2:T}${3:, arg}
endsnippet
snippet || "Closure, anonymous function (inline)" i
2017-02-11 13:01:38 +00:00
${1:move }|$2| { $3 }
2015-03-14 20:02:10 +00:00
endsnippet
snippet |} "Closure, anonymous function (block)" i
2017-02-11 13:01:38 +00:00
${1:move }|$2| {
2015-03-14 20:02:10 +00:00
$3
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet pri "print!(..)" b
2017-02-11 13:01:38 +00:00
print!("$1"${2/..*/, /}$2);
2014-04-18 12:58:02 +00:00
endsnippet
snippet pln "println!(..)" b
2017-02-11 13:01:38 +00:00
println!("$1"${2/..*/, /}$2);
2014-04-18 12:58:02 +00:00
endsnippet
2014-07-02 11:18:18 +00:00
snippet fmt "format!(..)"
2017-02-11 13:01:38 +00:00
format!("$1"${2/..*/, /}$2);
2014-07-02 11:18:18 +00:00
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet macro "macro_rules!" b
2016-03-14 10:04:57 +00:00
macro_rules! ${1:name} {
2014-07-02 11:18:18 +00:00
(${2:matcher}) => (
2017-02-11 13:01:38 +00:00
$3
2014-07-02 11:18:18 +00:00
)
2016-03-14 10:04:57 +00:00
}
2014-07-02 11:18:18 +00:00
endsnippet
2014-04-18 12:58:02 +00:00
2015-03-14 20:02:10 +00:00
snippet mod "A module" b
2014-04-18 12:58:02 +00:00
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
2017-02-11 13:01:38 +00:00
${VISUAL}$0
2014-07-02 11:18:18 +00:00
}
2014-04-18 12:58:02 +00:00
endsnippet
snippet for "for .. in .." b
2017-02-11 13:01:38 +00:00
for ${1:i} in $2 {
${VISUAL}$0
2014-04-18 12:58:02 +00:00
}
endsnippet
snippet todo "A Todo comment"
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
endsnippet
snippet st "Struct" b
2014-07-02 11:18:18 +00:00
struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
2017-02-11 13:01:38 +00:00
${VISUAL}$0
2014-04-18 12:58:02 +00:00
}
endsnippet
2015-03-14 20:02:10 +00:00
# TODO: fancy dynamic field mirroring like Python slotclass
2014-04-18 12:58:02 +00:00
snippet stn "Struct with new constructor." b
2014-07-02 11:18:18 +00:00
pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
2017-02-11 13:01:38 +00:00
fd$0
2014-04-18 12:58:02 +00:00
}
impl $1 {
2017-02-11 13:01:38 +00:00
pub fn new($2) -> $1 {
$1 { $3 }
2014-04-18 12:58:02 +00:00
}
}
endsnippet
2015-03-14 20:02:10 +00:00
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}} {
2017-02-11 13:01:38 +00:00
$0
2015-03-14 20:02:10 +00:00
}
endsnippet
2014-04-18 12:58:02 +00:00
# vim:ft=snippets: