Skip to content

Instantly share code, notes, and snippets.

use std::iter::Iterator;
struct Foo {
offset:uint,
x:[int, ..8]
}
impl Iterator<(* mut Foo, int)> for Foo {
fn next(& mut self) -> Option<(* mut Foo, int)> {
if self.offset > 0 {
@shadowmint
shadowmint / gist:11361488
Created April 28, 2014 04:02
Memory tests
extern crate libc;
use libc::c_void;
use std::ops::Drop;
use std::intrinsics::forget;
use std::ptr::swap;
struct Foo { x: int }
impl Drop for Foo {
macro_rules! trace(
($($arg:tt)*) => (
{ let x = ::std::io::stdout().write_line(format_args!(::std::fmt::format, $($arg)*)); println!("{}", x); }
);
)
pub fn do_something() -> uint {
return 99;
}
enum PyrsErr {
InternalErr
}
...
pub fn init() -> Result<*mut Struct_ppyData, PyrsErr> {
unsafe {
return Ok(ppy_init());
}
define(["require", "exports", 'jquery'], function(require, exports, $) {
requirejs.config({ baseUrl: "Scripts", paths: { jquery: "jquery-1.10.2" } }); // <--- Never gets used
$('#hello').click(); // <--- Won't work, because jquery won't be resolve to the right path
});
doug:rust-libs doug$ cat junk.rs
#![crate_id = "junk#0.1"]
use std::libc::c_int;
#[no_mangle]
pub extern fn dothing(a: c_int, b:c_int) -> c_int {
return a + b;
}
@shadowmint
shadowmint / gist:9948184
Last active August 29, 2015 13:58
Trait things
use _macros;
mod foo {
pub trait Foo {
fn hello(&self);
}
}
mod bar {
pub trait Foo {
@shadowmint
shadowmint / gist:9593771
Created March 17, 2014 03:59
Debug'd random reader
extern crate rand;
use std::io;
use std::num;
use std::io::BufferedReader;
use rand::{task_rng, Rng};
fn main() -> () {
@shadowmint
shadowmint / gist:9542616
Last active August 29, 2015 13:57
Crate with a macro
#[feature(macro_rules)];
#[crate_id = "junk#0.1"];
#[no_mangle]
pub fn dothing(a: int, b:int) -> int {
return a + b;
}
#[macro_escape]
@shadowmint
shadowmint / gist:9511455
Created March 12, 2014 17:06
Rust list example
use std::cast;
#[deriving(Show)]
struct Node<T> {
next:Option<~Node<T>>,
data:Option<T>
}
enum NodeErr {
Nope