Skip to content

Instantly share code, notes, and snippets.

View pzol's full-sized avatar

Piotr Zolnierek pzol

View GitHub Profile
@pzol
pzol / compare_ci.rs
Created January 26, 2014 19:24
compare two strings ignoring case
fn compare_ci(x: &str, y: &str) -> bool {
if x.char_len() != y.char_len() {
return false;
}
let mut it = x.chars().zip(y.chars());
it.all(|(x,y)|
unsafe {
x.to_ascii_nocheck().to_lower() == y.to_ascii_nocheck().to_lower()
}
#[ crate_id = "vmod_rpm#0.1" ];
// #[ crate_type = "lib" ];
#[ no_std ];
// #[ allow(ctypes) ];
// #[no_mangle]
// pub extern fn add(lhs: uint, rhs: uint) -> uint {
// lhs + rhs
// }
@pzol
pzol / test.rs
Created January 30, 2014 13:23
use std::sync::atomics::{ AtomicUint, INIT_ATOMIC_UINT, Ordering, AcqRel };
static counter: AtomicUint = INIT_ATOMIC_UINT;
fn call() -> uint {
let current = counter.fetch_add(1, AcqRel);
current.clone()
}
#[ crate_id = "vmod_rpm#0.1" ];
#[ crate_type = "dylib" ];
// #[ no_std ];
#[ allow(ctypes) ];
extern mod extra;
use std::str;
use std::sync::atomics;
use std::sync::atomics::{ AtomicUint, AcqRel };
use std::hashmap::HashMap;
#[test]
fn test(){
let mut omap: Option<HashMap<~str, uint>> = None;
omap = Some(HashMap::new());
let must_insert = false;
{
use std::hashmap::HashMap;
#[test]
fn test_mangle(){
let mut map = HashMap::<~str, uint>::new();
assert!(!map.contains_key(&~"foo"));
map.mangle(~"foo", 1,
|_k, a| a + 10,
|_k, v, a| *v -= 2
#[test]
fn test_iter(){
let mut map = HashMap::<~str, uint>::new();
map.insert(~"foo", 1);
map.insert(~"bar", 2);
let mut numbers = ~[];
for (_k,v) in map.iter() {
numbers.push(v.clone());
}
trait A {}
trait B {}
fn foo<t: A>() {
}
fn foo<t: B>() {
#[deriving(Eq)]
struct ParamsBuilder {
foo: uint,
bar: ~str,
baz: uint,
run: bool
}
impl ParamsBuilder {
struct Foo<'a> {
name: &'a str
}
impl<'a> Foo<'a> {
fn name(&'a mut self, s: &'a str) -> &'a mut Foo<'a> {
self.name = s;
self
}