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

253 lines
4.1 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
snippet fn "A function, optionally with arguments and return type." b
2014-04-18 12:58:02 +00:00
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet test "Test function" b
2014-04-18 12:58:02 +00:00
#[test]
fn ${1:test_function_name}() {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet bench "Bench function" b
#[bench]
fn ${1:bench_function_name}(b: &mut test::Bencher) {
b.iter(|| {
${VISUAL}${0}
})
}
endsnippet
snippet new "A new function" b
2014-04-18 12:58:02 +00:00
pub fn new(${2}) -> ${1:Name} {
${VISUAL}${0}return $1 { ${3} };
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet main "The main function" b
2014-04-18 12:58:02 +00:00
pub fn main() {
${VISUAL}${0}
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet let "A let statement" b
let ${1:name}${3} = ${VISUAL}${2};
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet lmut "let mut = .." b
let mut ${1:name}${3} = ${VISUAL}${2};
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet pri "print!(..)" b
print!("${1}"${2/..*/, /}${2});
2014-04-18 12:58:02 +00:00
endsnippet
snippet pln "println!(..)" b
println!("${1}"${2/..*/, /}${2});
endsnippet
2014-07-02 11:18:18 +00:00
snippet fmt "format!(..)"
format!("${1}"${2/..*/, /}${2});
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet macro "macro_rules!" b
macro_rules! ${1:name} (
(${2:matcher}) => (
${3}
)
)
endsnippet
2014-04-18 12:58:02 +00:00
snippet ec "extern crate ..." b
extern crate ${1:sync};
endsnippet
snippet ecl "...extern crate log;" b
#![feature(phase)]
#[phase(syntax, link)] extern crate log;
endsnippet
2014-07-02 11:18:18 +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"`} {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
}
2014-04-18 12:58:02 +00:00
endsnippet
snippet crate "Create header information" b
// Crate ID
#![crate_id = "${1:crate_name}#${2:0.0.1}"]
// Additional metadata attributes
#![desc = "${3:Descrption.}"]
#![license = "${4:BSD}"]
#![comment = "${5:Comment.}"]
// Specify the output type
#![crate_type = "${6:lib}"]
endsnippet
snippet allow "#[allow(..)]" b
#[allow(${1:unused_variable})]
endsnippet
snippet feat "#![feature(..)]" b
#![feature(${1:macro_rules})]
endsnippet
2014-07-02 11:18:18 +00:00
snippet der "#[deriving(..)]" b
#[deriving(${1:Show})]
endsnippet
snippet attr "#[..]" b
#[${1:inline}]
endsnippet
2014-04-18 12:58:02 +00:00
snippet opt "Option<..>"
Option<${1:int}>
endsnippet
snippet res "Result<.., ..>"
2014-07-02 11:18:18 +00:00
Result<${1:int}, ${2:()}>
2014-04-18 12:58:02 +00:00
endsnippet
2014-07-02 11:18:18 +00:00
snippet if "if .. (if)" b
if ${1} {
${VISUAL}${0}
}
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet el "else .. (el)"
else {
${VISUAL}${0}
}
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet eli "else if .. (eli)"
else if ${1} {
${VISUAL}${0}
}
endsnippet
2014-04-18 12:58:02 +00:00
2014-07-02 11:18:18 +00:00
snippet ife "if .. else (ife)"
if ${1} {
${2}
} else {
${3}
2014-04-18 12:58:02 +00:00
}
endsnippet
snippet mat "match"
match ${1} {
${2} => ${3},
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet loop "loop {}" b
loop {
${VISUAL}${0}
}
endsnippet
2014-04-18 12:58:02 +00:00
snippet while "while .. {}" b
2014-07-02 11:18:18 +00:00
while ${1} {
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
snippet for "for .. in .." b
for ${1:i} in ${2:range(0u, 10)} {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
snippet spawn "spawn(proc() { .. });" b
spawn(proc() {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
});
endsnippet
snippet chan "A channel" b
let (${1:tx}, ${2:rx}): (Sender<${3:int}>, Receiver<${4:int}>) = channel();
endsnippet
snippet duplex "Duplex stream" b
let (${1:from_child}, ${2:to_child}) = sync::duplex();
endsnippet
snippet todo "A Todo comment"
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
endsnippet
2014-07-02 11:18:18 +00:00
snippet fixme "FIXME comment"
// FIXME: ${1}
endsnippet
2014-04-18 12:58:02 +00:00
snippet st "Struct" b
2014-07-02 11:18:18 +00:00
struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
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"`} {
${3}
2014-04-18 12:58:02 +00:00
}
impl $1 {
pub fn new(${2}) -> $1 {
${4}return $1 {
${5}
};
}
}
endsnippet
snippet enum "An enum" b
2014-07-02 11:18:18 +00:00
enum ${1:Name} {
2014-04-18 12:58:02 +00:00
${VISUAL}${0},
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet type "A type" b
type ${1:NewName} = ${VISUAL}${0};
endsnippet
2014-04-18 12:58:02 +00:00
snippet imp "An impl" b
impl ${1:Name} {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
snippet drop "Drop implementation" b
impl Drop for ${1:Name} {
fn drop(&mut self) {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
}
endsnippet
2014-07-02 11:18:18 +00:00
snippet trait "Trait definition" b
2014-04-18 12:58:02 +00:00
trait ${1:Name} {
2014-07-02 11:18:18 +00:00
${VISUAL}${0}
2014-04-18 12:58:02 +00:00
}
endsnippet
snippet ss "A static string."
static ${1}: &'static str = "${VISUAL}${0}";
endsnippet
snippet stat "A static variable."
static ${1}: ${2:uint} = ${VISUAL}${0};
endsnippet
# vim:ft=snippets: