Skip to content

Add rust.snippets #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 215 additions & 0 deletions UltiSnips/rust.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#######################################################################
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to drop those comments as they only conflict in merge request without adding much useful

# Rust Snippets #
#######################################################################

###############
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for here - if you want to keep, a single line comment would be enough. Also there are other snippets below too, not only functions. I vote for kicking this.

# Functions #
###############
snippet fn "A function, optionally with arguments and return type."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all your snippets miss options. For example, this one could benefit from "b" I think.

fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to drop fillers lise /* code */ by now. You only have to go back and delete them if you want to put useful stuff there. ${VISUAL}$0 is better.

}
endsnippet

snippet test "Test function"
#[test]
fn ${1:test_function_name}() {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment about /* code */

}
endsnippet

snippet new "A new function"
pub fn new(${2}) -> ${1:Name} {
${VISUAL}${0}return $1 { ${3} };
}
endsnippet

snippet main "The main function"
pub fn main() {
${VISUAL}${0}
}
endsnippet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so many empty lines?



snippet let "A let statement"
let ${1:name}${3} = ${VISUAL}${2};
endsnippet

snippet pln "println!(..)" b
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, now I see snippet options. So you might have them left out on purpose above?

println!("${1}"${2/..*/, /}${2});
endsnippet



snippet ec "extern crate ..." b
extern crate ${1:sync};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 'sync' here? Is it meant to be deleted sometimes or replaced through another word? If deletetion is an option, make the " " before the word go away if $1 is empty.

endsnippet

snippet ecl "...extern crate log;" b
#![feature(phase)]
#[phase(syntax, link)] extern crate log;
endsnippet

snippet mod "A mod." b
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why so many spaces after mod?

mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
} /* $1 */
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}"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cries for using complete(). See python snippets.

endsnippet

snippet allow "#[allow(..)]" b
#[allow(${1:unused_variable})]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also cries for complete()

endsnippet

snippet feat "#![feature(..)]" b
#![feature(${1:macro_rules})]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too?

endsnippet


##################
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kill comment?

# Common types #
##################
snippet opt "Option<..>"
Option<${1:int}>
endsnippet

snippet res "Result<.., ..>"
Result<${1:~str}, ${2:()}>
endsnippet

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one empty line?




snippet if "if .. (if)" b
if ${1:/* condition */} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no /* code */

}
endsnippet

snippet mat "match"
match ${1} {
${2} => ${3},
}
endsnippet

snippet while "while .. {}" b
while ${1:condition} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet

snippet for "for .. in .." b
for ${1:i} in ${2:range(0u, 10)} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet

snippet spawn "spawn(proc() { .. });" b
spawn(proc() {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
});
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

#####################
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should not be in public snippets except when there is a language default for the format. TODO formats are to varied and personal.

# TODO commenting #
#####################
snippet todo "A Todo comment"
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
endsnippet


############
# Struct #
############
snippet st "Struct" b
struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet

snippet stn "Struct with new constructor." b
pub struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
${3:/* code */}
}

impl $1 {
pub fn new(${2}) -> $1 {
${4}return $1 {
${5}
};
}
}
endsnippet


##########
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the comments become silly - only for one snippet each.

# Enum #
##########
snippet enum "An enum" b
enum ${1:enum_name} {
${VISUAL}${0},
}
endsnippet


##########
# Impl #
##########
snippet imp "An impl" b
impl ${1:Name} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet

snippet drop "Drop implementation" b
impl Drop for ${1:Name} {
fn drop(&mut self) {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
}
endsnippet


############
# Traits #
############
snippet trait "Trait block" b
trait ${1:Name} {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet


#############
# Statics #
#############
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line should no longer be needed.