New snippets and cleanup for Rust
This commit is contained in:
parent
5470b2f348
commit
c80c281219
@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
priority -50
|
priority -50
|
||||||
|
|
||||||
###############
|
|
||||||
# Functions #
|
|
||||||
###############
|
|
||||||
snippet fn "A function, optionally with arguments and return type." b
|
snippet fn "A function, optionally with arguments and return type." b
|
||||||
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
|
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
@ -20,6 +17,16 @@ fn ${1:test_function_name}() {
|
|||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
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
|
snippet new "A new function" b
|
||||||
pub fn new(${2}) -> ${1:Name} {
|
pub fn new(${2}) -> ${1:Name} {
|
||||||
${VISUAL}${0}return $1 { ${3} };
|
${VISUAL}${0}return $1 { ${3} };
|
||||||
@ -32,17 +39,33 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
snippet let "A let statement" b
|
snippet let "A let statement" b
|
||||||
let ${1:name}${3} = ${VISUAL}${2};
|
let ${1:name}${3} = ${VISUAL}${2};
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet lmut "let mut = .." b
|
||||||
|
let mut ${1:name}${3} = ${VISUAL}${2};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet pri "print!(..)" b
|
||||||
|
print!("${1}"${2/..*/, /}${2});
|
||||||
|
endsnippet
|
||||||
|
|
||||||
snippet pln "println!(..)" b
|
snippet pln "println!(..)" b
|
||||||
println!("${1}"${2/..*/, /}${2});
|
println!("${1}"${2/..*/, /}${2});
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet fmt "format!(..)"
|
||||||
|
format!("${1}"${2/..*/, /}${2});
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet macro "macro_rules!" b
|
||||||
|
macro_rules! ${1:name} (
|
||||||
|
(${2:matcher}) => (
|
||||||
|
${3}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
endsnippet
|
||||||
|
|
||||||
snippet ec "extern crate ..." b
|
snippet ec "extern crate ..." b
|
||||||
extern crate ${1:sync};
|
extern crate ${1:sync};
|
||||||
@ -53,10 +76,10 @@ snippet ecl "...extern crate log;" b
|
|||||||
#[phase(syntax, link)] extern crate log;
|
#[phase(syntax, link)] extern crate log;
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet mod "A mod." b
|
snippet mod "A module" b
|
||||||
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
|
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
} /* $1 */
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet crate "Create header information" b
|
snippet crate "Create header information" b
|
||||||
@ -80,35 +103,58 @@ snippet feat "#![feature(..)]" b
|
|||||||
#![feature(${1:macro_rules})]
|
#![feature(${1:macro_rules})]
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet der "#![deriving(..)]" b
|
||||||
|
#![deriving(${1:Show})]
|
||||||
|
endsnippet
|
||||||
|
|
||||||
##################
|
|
||||||
# Common types #
|
|
||||||
##################
|
|
||||||
snippet opt "Option<..>"
|
snippet opt "Option<..>"
|
||||||
Option<${1:int}>
|
Option<${1:int}>
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet res "Result<.., ..>"
|
snippet res "Result<.., ..>"
|
||||||
Result<${1:~str}, ${2:()}>
|
Result<${1:int}, ${2:()}>
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
snippet if "if .. (if)" b
|
snippet if "if .. (if)" b
|
||||||
if ${1:/* condition */} {
|
if ${1} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet el "else .. (el)"
|
||||||
|
else {
|
||||||
|
${VISUAL}${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet eli "else if .. (eli)"
|
||||||
|
else if ${1} {
|
||||||
|
${VISUAL}${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet ife "if .. else (ife)"
|
||||||
|
if ${1} {
|
||||||
|
${2}
|
||||||
|
} else {
|
||||||
|
${3}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
snippet mat "match"
|
snippet mat "match"
|
||||||
match ${1} {
|
match ${1} {
|
||||||
${2} => ${3},
|
${2} => ${3},
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet loop "loop {}" b
|
||||||
|
loop {
|
||||||
|
${VISUAL}${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
snippet while "while .. {}" b
|
snippet while "while .. {}" b
|
||||||
while ${1:condition} {
|
while ${1} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
@ -133,25 +179,22 @@ snippet duplex "Duplex stream" b
|
|||||||
let (${1:from_child}, ${2:to_child}) = sync::duplex();
|
let (${1:from_child}, ${2:to_child}) = sync::duplex();
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
#####################
|
|
||||||
# TODO commenting #
|
|
||||||
#####################
|
|
||||||
snippet todo "A Todo comment"
|
snippet todo "A Todo comment"
|
||||||
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
|
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet fixme "FIXME comment"
|
||||||
|
// FIXME: ${1}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
############
|
|
||||||
# Struct #
|
|
||||||
############
|
|
||||||
snippet st "Struct" b
|
snippet st "Struct" b
|
||||||
struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
|
struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet stn "Struct with new constructor." b
|
snippet stn "Struct with new constructor." b
|
||||||
pub struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
|
pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
|
||||||
${3}
|
${3}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,20 +207,16 @@ impl $1 {
|
|||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
##########
|
|
||||||
# Enum #
|
|
||||||
##########
|
|
||||||
snippet enum "An enum" b
|
snippet enum "An enum" b
|
||||||
enum ${1:enum_name} {
|
enum ${1:Name} {
|
||||||
${VISUAL}${0},
|
${VISUAL}${0},
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet type "A type" b
|
||||||
|
type ${1:NewName} = ${VISUAL}${0};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
##########
|
|
||||||
# Impl #
|
|
||||||
##########
|
|
||||||
snippet imp "An impl" b
|
snippet imp "An impl" b
|
||||||
impl ${1:Name} {
|
impl ${1:Name} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
@ -192,20 +231,12 @@ impl Drop for ${1:Name} {
|
|||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
snippet trait "Trait definition" b
|
||||||
############
|
|
||||||
# Traits #
|
|
||||||
############
|
|
||||||
snippet trait "Trait block" b
|
|
||||||
trait ${1:Name} {
|
trait ${1:Name} {
|
||||||
${VISUAL}${0}
|
${VISUAL}${0}
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
#############
|
|
||||||
# Statics #
|
|
||||||
#############
|
|
||||||
snippet ss "A static string."
|
snippet ss "A static string."
|
||||||
static ${1}: &'static str = "${VISUAL}${0}";
|
static ${1}: &'static str = "${VISUAL}${0}";
|
||||||
endsnippet
|
endsnippet
|
||||||
|
Loading…
Reference in New Issue
Block a user