Setting up a Rust Development Environment.

Printing a simple “Hello World” main;

fn main() {
println!(“Hello World!”);
}

 

The easiest way to run:

rustc hello.rs

./hello (notice the compiled file doesn’t have any extensions)

 

Now some tinkering:

If you’re using vim and a little lazy like me to type the compile command and run it each and every time, just map an unused key let’s say “F9” to auto-compile and run your file.

To do so on vim, add the following line to your .vimrc

Screenshot from 2018-02-12 17-41-06

 

:w          -> write changes to the file.

:!clear  -> clear the output of the previous commands to run ie: when compilation failed or run successfully.

:!rustc  -> invoke the compiler to compile the file.

%          -> used to denote the current file name, can have any extensions (test.rs).

&&       -> and.

./%<      -> run the compiled output file and notice the  “<“, it tells vim to remove the extension. test.rs will become test.

 

Setting up auto-completion:

Better yet, you can use YouCompleteMe (YCM) to facilitate your work, just build YCM with the –rust-completer

I use vim-plug (set it up, easy just follow Github instruction) to install plugins on vim, I added this line to my .vimrc

” YouCompleteMe
Plug ‘Valloric/YouCompleteMe’, { ‘do’: ‘./install.py –clang-completer –rust-completer’ }

” is a comment

–clang-completer is used for autocompletion of C programs

then run :PluginUpdate and your plugins will start updating and installing.

snippets below showing how the auto-completion is working

Screenshot from 2018-02-12 21-31-03

 

Now that you have a fully functional development environment, you can start coding,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s