vim-snippets/UltiSnips/rust.snippets

107 lines
2.1 KiB
Plaintext
Raw Normal View History

2014-04-08 10:18:29 -04:00
#######################################################################
# Rust Snippets #
#######################################################################
2014-04-18 04:02:36 -04:00
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."
2014-04-08 10:18:29 -04:00
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
${VISUAL}${0}
2014-04-08 10:18:29 -04:00
}
endsnippet
2015-08-02 07:56:54 -04:00
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
2014-05-31 07:40:59 -04:00
snippet pri "print!(..)" b
print!("${1}"${2/..*/, /}${2});
endsnippet
2014-04-08 10:18:29 -04:00
snippet pln "println!(..)" b
println!("${1}"${2/..*/, /}${2});
endsnippet
2014-05-31 07:40:59 -04:00
snippet fmt "format!(..)"
format!("${1}"${2/..*/, /}${2});
endsnippet
2014-04-08 10:18:29 -04:00
2014-05-31 07:40:59 -04:00
snippet macro "macro_rules!" b
macro_rules! ${1:name} (
(${2:matcher}) => (
${3}
)
)
endsnippet
2014-04-08 10:18:29 -04:00
snippet mod "A module" b
2014-04-08 10:18:29 -04:00
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
${VISUAL}${0}
2014-05-31 07:40:59 -04:00
}
2014-04-08 10:18:29 -04:00
endsnippet
snippet for "for .. in .." b
2015-05-17 14:55:08 -04:00
for ${1:i} in ${2} {
${VISUAL}${0}
2014-04-08 10:18:29 -04:00
}
endsnippet
snippet todo "A Todo comment"
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
endsnippet
snippet st "Struct" b
2014-05-31 07:40:59 -04:00
struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
${VISUAL}${0}
2014-04-08 10:18:29 -04:00
}
endsnippet
# TODO: fancy dynamic field mirroring like Python slotclass
2014-04-08 10:18:29 -04:00
snippet stn "Struct with new constructor." b
2014-05-31 07:40:59 -04:00
pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
fd${0}
2014-04-08 10:18:29 -04:00
}
impl $1 {
pub fn new(${2}) -> $1 {
$1 { ${3} };
2014-04-08 10:18:29 -04:00
}
}
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
2014-04-08 10:18:29 -04:00
# vim:ft=snippets: