2014-07-02 07:18:18 -04:00
|
|
|
#################
|
|
|
|
# Rust Snippets #
|
|
|
|
#################
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
snippet fn
|
2015-01-18 07:58:28 -05:00
|
|
|
fn ${1:function_name}(${2})${3} {
|
2014-07-02 07:18:18 -04:00
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet test
|
|
|
|
#[test]
|
|
|
|
fn ${1:test_function_name}() {
|
|
|
|
${0}
|
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet bench "Bench function" b
|
|
|
|
#[bench]
|
|
|
|
fn ${1:bench_function_name}(b: &mut test::Bencher) {
|
|
|
|
b.iter(|| {
|
|
|
|
${0}
|
|
|
|
})
|
|
|
|
}
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet new
|
|
|
|
pub fn new(${2}) -> ${1:Name} {
|
|
|
|
${0}return $1 { ${3} };
|
|
|
|
}
|
|
|
|
snippet main
|
|
|
|
pub fn main() {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet let
|
2015-01-18 07:58:28 -05:00
|
|
|
let ${1:name: type} = ${2};
|
|
|
|
snippet let
|
|
|
|
let mut ${1:name: type} = ${2};
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet pln
|
|
|
|
println!("${1}");
|
|
|
|
snippet pln,
|
|
|
|
println!("${1}", ${2});
|
|
|
|
snippet ec
|
|
|
|
extern crate ${1:sync};
|
|
|
|
snippet ecl
|
|
|
|
#![feature(phase)]
|
2014-09-27 11:32:18 -04:00
|
|
|
#[phase(plugin, link)] extern crate log;
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet mod
|
|
|
|
mod ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
|
|
|
|
${0}
|
|
|
|
} /* $1 */
|
|
|
|
snippet crate
|
2014-09-27 11:32:18 -04:00
|
|
|
// Crate name
|
|
|
|
#![crate_name = "${1:crate_name}"]
|
2014-07-02 07:18:18 -04:00
|
|
|
// Additional metadata attributes
|
2014-09-27 11:32:18 -04:00
|
|
|
#![desc = "${2:Descrption.}"]
|
|
|
|
#![license = "${3:BSD}"]
|
|
|
|
#![comment = "${4:Comment.}"]
|
2014-07-02 07:18:18 -04:00
|
|
|
// Specify the output type
|
2014-09-27 11:32:18 -04:00
|
|
|
#![crate_type = "${5:lib}"]
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet allow
|
|
|
|
#[allow(${1:unused_variable})]
|
|
|
|
snippet feat
|
|
|
|
#![feature(${1:macro_rules})]
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet der "#[deriving(..)]" b
|
|
|
|
#[deriving(${1:Show})]
|
|
|
|
snippet attr "#[..]" b
|
|
|
|
#[${1:inline}]
|
|
|
|
|
2014-07-02 07:18:18 -04:00
|
|
|
# Common types
|
|
|
|
snippet opt
|
|
|
|
Option<${1:int}>
|
|
|
|
snippet res
|
|
|
|
Result<${1:~str}, ${2:()}>
|
|
|
|
snippet if
|
2015-01-18 07:58:28 -05:00
|
|
|
if ${1} {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet ife
|
|
|
|
if ${1} {
|
|
|
|
${2}
|
|
|
|
} else {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet el
|
|
|
|
else {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet eli
|
|
|
|
else if ${1} {
|
2014-07-02 07:18:18 -04:00
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet mat
|
|
|
|
match ${1} {
|
|
|
|
${2} => ${3},
|
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet loop "loop {}" b
|
|
|
|
loop {
|
|
|
|
${0}
|
|
|
|
}
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet while
|
|
|
|
while ${1:condition} {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet for
|
2015-01-18 07:58:28 -05:00
|
|
|
for ${1:i} in ${2:0u..10} {
|
2014-07-02 07:18:18 -04:00
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet spawn
|
|
|
|
spawn(proc() {
|
|
|
|
${0}
|
|
|
|
});
|
|
|
|
snippet chan
|
|
|
|
let (${1:tx}, ${2:rx}): (Sender<${3:int}>, Receiver<${4:int}>) = channel();
|
|
|
|
snippet duplex
|
|
|
|
let (${1:from_child}, ${2:to_child}) = sync::duplex();
|
|
|
|
# TODO commenting
|
|
|
|
snippet todo
|
2015-01-18 07:58:28 -05:00
|
|
|
// [TODO]: ${0:Description}
|
|
|
|
snippet fixme "FIXME comment"
|
|
|
|
// FIXME: $0
|
|
|
|
|
2014-07-02 07:18:18 -04:00
|
|
|
# Struct
|
|
|
|
snippet st
|
|
|
|
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
|
|
|
|
${0}
|
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet stn
|
|
|
|
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
|
|
|
|
${0}
|
|
|
|
}
|
2014-07-02 07:18:18 -04:00
|
|
|
|
|
|
|
impl $1 {
|
|
|
|
pub fn new(${2}) -> $1 {
|
|
|
|
${4}return $1 {
|
|
|
|
${5}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2015-01-18 07:58:28 -05:00
|
|
|
snippet typ
|
|
|
|
type ${1:NewName} = $0;
|
2014-07-02 07:18:18 -04:00
|
|
|
# Enum
|
|
|
|
snippet enum
|
2015-01-18 07:58:28 -05:00
|
|
|
enum ${1:Name} {
|
2014-07-02 07:18:18 -04:00
|
|
|
${0},
|
|
|
|
}
|
|
|
|
# Impl
|
|
|
|
snippet imp
|
|
|
|
impl ${1:Name} {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet drop
|
|
|
|
impl Drop for ${1:Name} {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Traits
|
|
|
|
snippet trait
|
|
|
|
trait ${1:Name} {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
# Statics
|
|
|
|
snippet ss
|
|
|
|
static ${1}: &'static str = "${0}";
|
|
|
|
snippet stat
|
2015-01-18 07:58:28 -05:00
|
|
|
static ${1}: ${2:usize} = ${0};
|