1
0
Fork 0
mirror of synced 2024-11-04 16:38:59 -05:00
ultimate-vim/sources_non_forked/vim-snippets/snippets/rust.snippets

194 lines
4.1 KiB
Text
Raw Normal View History

2014-07-02 07:18:18 -04:00
#################
# Rust Snippets #
#################
# Functions
2015-03-14 16:02:10 -04:00
snippet fn "Function definition"
2015-01-18 07:58:28 -05:00
fn ${1:function_name}(${2})${3} {
2014-07-02 07:18:18 -04:00
${0}
}
2015-12-08 08:20:04 -05:00
snippet pfn "Function definition"
pub fn ${1:function_name}(${2})${3} {
${0}
}
2015-03-14 16:02:10 -04:00
snippet test "Unit test function"
2014-07-02 07:18:18 -04:00
#[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}
})
}
2015-03-14 16:02:10 -04:00
snippet new "Constructor function"
2014-07-02 07:18:18 -04:00
pub fn new(${2}) -> ${1:Name} {
2016-03-14 06:04:57 -04:00
$1 { ${3} }
2014-07-02 07:18:18 -04:00
}
2015-03-14 16:02:10 -04:00
snippet main "Main function"
2014-07-02 07:18:18 -04:00
pub fn main() {
${0}
}
2016-02-20 08:13:10 -05:00
snippet let "let variable declaration with type inference"
2017-02-11 08:01:38 -05:00
let ${1} = ${2};
2016-02-20 08:13:10 -05:00
snippet lett "let variable declaration with explicit type annotation"
2017-07-06 08:57:35 -04:00
let ${1}: ${2} = ${3};
2016-02-20 08:13:10 -05:00
snippet letm "let mut variable declaration with type inference"
2017-07-06 08:57:35 -04:00
let mut ${1} = ${2};
2016-02-20 08:13:10 -05:00
snippet lettm "let mut variable declaration with explicit type annotation"
2017-07-06 08:57:35 -04:00
let mut ${1}: ${2} = ${3};
2017-05-02 08:42:08 -04:00
snippet pri "print!"
print!("${1}");
snippet pri, "print! with format param"
print!("${1}", ${2});
2015-03-14 16:02:10 -04:00
snippet pln "println!"
2014-07-02 07:18:18 -04:00
println!("${1}");
2015-03-14 16:02:10 -04:00
snippet pln, "println! with format param"
2014-07-02 07:18:18 -04:00
println!("${1}", ${2});
2017-05-02 08:42:08 -04:00
snippet fmt "format!"
format!("${1}", ${2});
2015-03-14 16:02:10 -04:00
# Modules
snippet ec "extern crate"
2014-07-02 07:18:18 -04:00
extern crate ${1:sync};
2015-03-14 16:02:10 -04:00
snippet ecl "extern crate log"
#[macro_use]
extern crate log;
2014-07-02 07:18:18 -04:00
snippet mod
mod ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
} /* $1 */
2015-03-14 16:02:10 -04:00
snippet testmod "Test module" b
#[cfg(test)]
mod tests {
use super::${1:*};
test${0}
}
# Attributes
snippet allow "allow lint attribute" b
#[allow(${1:unused_variable})]
snippet cfg "cfg attribute" b
#[cfg(${1:target_os = "linux"})]
snippet feat "feature attribute" b
#![feature(${1:plugin})]
snippet der "#[derive(..)]" b
#[derive(${1:Debug})]
snippet attr "#[..]" b
#[${1:inline}]
snippet crate "Define create meta attributes"
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
# Common types
2015-03-14 16:02:10 -04:00
snippet opt "Option<T>"
Option<${1:i32}>
snippet res "Result<T, E>"
2014-07-02 07:18:18 -04:00
Result<${1:~str}, ${2:()}>
2015-03-14 16:02:10 -04:00
# Control structures
2014-07-02 07:18:18 -04:00
snippet if
2015-01-18 07:58:28 -05:00
if ${1} {
2017-02-11 08:01:38 -05:00
${0:${VISUAL}}
2015-01-18 07:58:28 -05:00
}
2015-03-14 16:02:10 -04:00
snippet ife "if / else"
2015-01-18 07:58:28 -05:00
if ${1} {
2017-02-11 08:01:38 -05:00
${2:${VISUAL}}
2015-01-18 07:58:28 -05:00
} else {
${0}
}
2015-03-14 16:02:10 -04:00
snippet el "else"
2015-01-18 07:58:28 -05:00
else {
2017-02-11 08:01:38 -05:00
${0:${VISUAL}}
2015-01-18 07:58:28 -05:00
}
2015-03-14 16:02:10 -04:00
snippet eli "else if"
2015-01-18 07:58:28 -05:00
else if ${1} {
2017-02-11 08:01:38 -05:00
${0:${VISUAL}}
2014-07-02 07:18:18 -04:00
}
2015-03-14 16:02:10 -04:00
snippet mat "match pattern"
2014-07-02 07:18:18 -04:00
match ${1} {
2015-03-14 16:02:10 -04:00
${2} => ${3}
2014-07-02 07:18:18 -04:00
}
2015-03-14 16:02:10 -04:00
snippet case "Case clause of pattern match"
${1:_} => ${2:expression}
2015-01-18 07:58:28 -05:00
snippet loop "loop {}" b
loop {
2017-02-11 08:01:38 -05:00
${0:${VISUAL}}
2015-01-18 07:58:28 -05:00
}
2015-12-08 08:20:04 -05:00
snippet wh "while loop"
2014-07-02 07:18:18 -04:00
while ${1:condition} {
2017-02-11 08:01:38 -05:00
${0:${VISUAL}}
2014-07-02 07:18:18 -04:00
}
2015-03-14 16:02:10 -04:00
snippet for "for ... in ... loop"
2015-07-13 06:22:46 -04:00
for ${1:i} in ${2} {
2014-07-02 07:18:18 -04:00
${0}
}
# TODO commenting
2015-03-14 16:02:10 -04:00
snippet todo "TODO comment"
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
2015-03-14 16:02:10 -04:00
snippet st "Struct definition"
2014-07-02 07:18:18 -04:00
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
}
2015-03-14 16:02:10 -04:00
snippet impl "Struct/Trait implementation"
impl ${1:Type/Trait}${2: for ${3:Type}} {
${0}
}
snippet stn "Struct with new constructor"
pub struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
2015-01-18 07:58:28 -05:00
${0}
}
2014-07-02 07:18:18 -04:00
impl $1 {
2017-03-07 12:04:28 -05:00
pub fn new(${2}) -> Self {
2016-03-14 06:04:57 -04:00
$1 { ${3} }
2014-07-02 07:18:18 -04:00
}
}
2015-03-14 16:02:10 -04:00
snippet type "Type alias"
type ${1:NewName} = $2;
snippet enum "enum definition"
2015-01-18 07:58:28 -05:00
enum ${1:Name} {
2015-03-14 16:02:10 -04:00
${2},
2014-07-02 07:18:18 -04:00
}
2015-03-14 16:02:10 -04:00
# Traits
snippet trait "Trait definition"
trait ${1:Name} {
2014-07-02 07:18:18 -04:00
${0}
}
2015-03-14 16:02:10 -04:00
snippet drop "Drop trait implementation (destructor)"
2014-07-02 07:18:18 -04:00
impl Drop for ${1:Name} {
fn drop(&mut self) {
${0}
}
}
# Statics
2015-03-14 16:02:10 -04:00
snippet ss "static string declaration"
2014-07-02 07:18:18 -04:00
static ${1}: &'static str = "${0}";
2015-03-14 16:02:10 -04:00
snippet stat "static item declaration"
2015-01-18 07:58:28 -05:00
static ${1}: ${2:usize} = ${0};
2015-03-14 16:02:10 -04:00
# Concurrency
snippet scoped "spawn a scoped thread"
thread::scoped(${1:move }|| {
${0}
});
snippet spawn "spawn a thread"
thread::spawn(${1:move }|| {
${0}
});
snippet chan "Declare (Sender, Receiver) pair of asynchronous channel()"
let (${1:tx}, ${2:rx}): (Sender<${3:i32}>, Receiver<${4:i32}>) = channel();
# Testing
snippet as "assert!"
2017-07-06 08:57:35 -04:00
assert!(${1:predicate});
2015-03-14 16:02:10 -04:00
snippet ase "assert_eq!"
2017-07-06 08:57:35 -04:00
assert_eq!(${1:expected}, ${2:actual});