Archive for the ‘Rust’ Category
Import Rust file to RustyCage
The import Rust file wizard will copy a file from your file system into your current workspace in Eclipse. So from the “File” menu chose Import.
Then from the Import wizard you have the Rust category and in there you can chose Rust file. The Import Rust Project is not implemented as for now. Sorry.
Then press the “next>” button and chose the “src” folder.
Then press the “browse” button or enter the path to your file.
Then press the “Finish” button.
And viola, your Rust file is imported/copied into your workspace and project.
Introducing Rust Task
So what is Rust then, from Wikipedia “Rust is an experimental, concurrent, multi-paradigm, compiled programming language developed by Mozilla Labs. It is designed to be practical, supporting pure-functional, concurrent-actor, imperative-procedural, and object-oriented styles.”
The most exiting thing for me is that it is influenced by Erlang and Limbo. Limbo with ports and channels and Erlang with the lightweight processes. I guess that Rust is designed with the purpose of writing web browser and to handle concurrency in a multi-core environment, these characteristics are well suited for backend systems as well.
In Rust we spawn out a new task, with the spawn keyword. This creates a lightweight process/task in which we can communicate with messages through channels. Default behavior for a variable in Rust is to be immutable, if you want a mutable variable you must explicitly declare it mutable with the mutable keyword.
So here is a little silly demo code of how to spawn a task and to send and receive messages from it.
use std; import print = io:: println; fn main() { let port = comm:: port::(); let chan = comm:: chan::(port); do task:: spawn || { let result = compute_some(); comm:: send(chan, result); } let first_result = compute_another(); let second_result = comm::recv(port); print(#fmt("First, %s", first_result)); print(#fmt("Second, %s", second_result)); } fn compute_some() -> str { ret "Some computation"; } fn compute_another() -> str { ret "Another computation"; }
I create two functions compute_some() and compute_another() in which only returns a string to recognize which function has been executed. Then in the main function I create a port and creates a channel connected to the port.Then I spawn out a task to compute where I execute the compute_some() function and sends the result on the channel.Then I execute one function and assign the result to a variable and then fetches the result from the channel and assigns it to a second variable. Then prints the result. Not very needy of concurrency here, but I guess you get the point.
For more on Rust Rust-lang I recommend the tutorial. Rust tutorail
RustyCage a Rust-lang IDE plugin for Eclipse
I have created a Rust plugin for Eclipse, so here is a small intro how to use it.
First you need to chose the Rust perspective.
If you want code completion from the std libs, you need to download the rust source code and add rust home your rust preferences.
Then in the Rust perspective chose New RustProject
This opens the rust project wizard.
The default is lib, so if you want a executable you need to check of the lib check box. And fill inn version and author. Here is an example.
Press Finnish and your rust project is created. A crate file is created for your project.
No you probably want a rust file, chose new rust file.
This will open the new rust file wizard. Give the file a name. The must be a .rs or .rc file.
Then your crate file has been updated with your new rust file.
Now enter your code in the rust file. And you have the compile and the run buttons in your task bar. Compile and run uses the context of the file you are in, so you can either compile the crate or just one file.
Compile output in the console window.
And finally press the run button and you get the result in the console window.
You can fetch the plugin via github from
https://github.com/reidarsollid/RustyCage
Or get it from update site
https://sourceforge.net/projects/rustycage/files/updatesite/
RustyCage is writen in Scala so you need the Scala compiler to install it.
http://download.scala-ide.org/sdk/e38/scala210/stable/site
Build your own update site with maven and tycho
https://bitbucket.org/rsollid/tycho-rustycage