Rust Cologne/Bonn Meetup 29.07.2015
-
Upload
harris-brakmic -
Category
Technology
-
view
136 -
download
2
Transcript of Rust Cologne/Bonn Meetup 29.07.2015
RUST COLOGNE/BONN MEETUP
29. JULY 2015
WEBAPPS WITH NICKEL.RS, GULP, JAVASCRIPT (LINUX)
INTERFACING WITH C UNDER VISUAL STUDIO (WINDOWS)
A FEW THOUGHTS ON COMMUNITY BUILDING
ABOUT ME
• Harris Brakmic
• Software Engineer
• advarics GmbH, Innsbruck ( ) HQ, Bochum ( ) DEV, http://advarics.net
• Tech at work: .NET, Azure Cloud, C#, JavaScript, Backend-to-Frontend dev, mobile Apps
• Tech at home: pretending to learn Rust, claiming to know C, bragging about Linux (Kali, Fedora, Mint)
• http://brakmic.de
• @brakmic
• harris.brakmic
BUILDING WEBAPPS WITH RUST / NICKEL.RS
• OS: Linux Mint (it seems Nickel.rs won‘t compile under Win32)
• Stack: Gulp, NodeJS, RactiveJS (Frontend UI-Library), Nickel.rs
• For faster UI-Development Gulp & NodeJS can be used instead of Nickel.rs
• More info: http://nickel.rs
• Sources: https://github.com/brakmic/nickel-demo
NICKEL.RS
• Framework for Web Apps, written in Rust
• Similar to ExpressJS
• Extensible Architecture (Plugins, Middleware)
• Supports the „usual suspects“: Parameter-Access, Routing, Wildcards etc.
• Templating via Mustache
A VERY SIMPLE WEB SERVER*
#[macro_use] extern crate nickel;
use nickel::{Nickel, HttpRouter};
fn main() {
let mut server = Nickel::new();
server.get("**", middleware!("Hello Rustaceans!"));
server.listen("127.0.0.1:3000");
}
*shamelessly stolen from https://github.com/nickel-org/nickel.rs/blob/master/examples/hello_world.rs
TEMPLATING WITH NICKEL.RS
src/templates/hello.tpl
<div>
Hello {{ name }}
</div>
src/main.rs
server.get("/", middleware! { |_, res|
let mut data = HashMap::<&str, &str>::new();
data.insert("name", "Rustaceans");
return res.render(„src/templates/hello.tpl", &data)
});
RUST UNDER WIN32 WITH VS2013 + VISUALRUST
• OS: Windows 8.1x64 + Visual Studio 2013
• VisualRust Addin from https://github.com/PistonDevelopers/VisualRust
• Development still in early phase!
• Some tweaks needed! (Cargo.toml not available by default)
• Pro-Tip: add two new entries (Cargo Build / Run) under Tools/External Tools
• Sources: https://github.com/brakmic/IHaveNoClue
PREPARATIONS: EXPORT, ADAPT, LINK• All function exports must be extern “C“ because Rust can‘t use C++ DLLs (name mangling, vptr etc.)
extern "C" IAMALIBRARY_API int SampleFunction(int a, int b);
extern "C" IAMALIBRARY_API void WriteContent(CarrierObject* obj);
• Implement proper mappings of C-structs
#[repr(C)]
pub struct CarrierObject{
pub a_value: int32_t}
• Link the library
#[link(name = "IAmALibrary")]
extern "C" {
fn SampleFunction(a: i32, b: i32) -> i32;
fn WriteContent(obj: *mut CarrierObject);
}
USAGE IN UNSAFE BLOCKS
• No Rust, no Safety!
• Therefore, when executing „unsafe“ operations like pointer arithmetic or calling C-DLLs, such calls must be packed into unsafe-blocks.
fn main() { Safely allocate the object on heap
let mut an_object = Box::new(CarrierObject{ a_value: 100 });
unsafe { WriteContent(&mut *an_object); }; Forward raw object-pointer to unsafe function
let answer = unsafe { SampleFunction(40,2) };
println!("The ultimate answer is {}", answer);
}
A FEW THOUGHTS ON COMMUNITY BUILDING
• Two new domains: http://rustaceans.de & http://rustaceans.cologne
• Some unfair criticism:
http://users.rust-lang.org is full of excellent material but relatively hard to search / filter.
Only a few general categories exist: announcements, help, „uncategorized“ and meta
A beginner (like me) quickly gets lost in the uncategorized sea of questions/answers.
• A possible alternative?
What about a new forum with better structure, easier information retrieval and (optionally)
German language?
• Forum example: http://forum.rustaceans.de
• What about establishing a frequent Rust meetup in the Cologne/Bonn area?
• Do we need a website?