Skip to content

Instantly share code, notes, and snippets.

@cceckman
cceckman / foo.cpp
Created March 5, 2014 04:17
Resizing a vector.
#include <cstdio>
#include <vector>
int main(){
int new_size = 3;
@cceckman
cceckman / mod.rs
Last active August 29, 2015 13:56
use self::arm1176jzf_s::gpio::pin_mode::OUTPUT;
// Compilation error: cannot import from a trait or type implementation
pub mod arm1176jzf_s;
// Defined with submodules in separate file
pub fn init() {
let p : Pin = arm1176jzf_s::gpio::Pin::get(16);
p.setMode(OUTPUT);
// setMode has a single parameter of type arm1176jzf_s::gpio::pin_mode; OUTPUT is a variant thereof
#include <stdio.h>
int i = 0; // Static values are initialized to 0 according to C spec, this just makes it explicit
int foo(){
i = i + 1;
return i;
}
int main(){
@cceckman
cceckman / gist:9214876
Created February 25, 2014 18:33
Method calls in Rust
trait ScreenCanvas{
fn sync(&Self) -> bool;
fn setResolution(&Self) -> bool;
}
struct screen_buffer_info{
x : uint;
}
impl ScreenCanvas for screen_buffer_info{
@cceckman
cceckman / error.log
Created February 20, 2014 07:45
Trait inheritance in Rust?
gist.rs:12:5: 16:6 error: method `add` is not a member of trait `vector<A>`
gist.rs:12 fn add(&self, rhs : &(A,A,A)) -> (A,A,A){
gist.rs:13 let (x,y,z) = *self;
gist.rs:14 let (a,b,c) = *rhs;