1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(box_syntax)]
13 use std::cell::RefCell;
15 pub struct Entry<A,B> {
20 pub struct alist<A,B> {
21 eq_fn: extern "Rust" fn(A,A) -> bool,
22 data: Box<RefCell<Vec<Entry<A,B>>>>,
25 pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
26 let mut data = lst.data.borrow_mut();
27 (*data).push(Entry{key:k, value:v});
30 pub fn alist_get<A:Clone + 'static,
35 let eq_fn = lst.eq_fn;
36 let data = lst.data.borrow();
37 for entry in &(*data) {
38 if eq_fn(entry.key.clone(), k.clone()) {
39 return entry.value.clone();
46 pub fn new_int_alist<B:'static>() -> alist<isize, B> {
47 fn eq_int(a: isize, b: isize) -> bool { a == b }
50 data: box RefCell::new(Vec::new()),
55 pub fn new_int_alist_2<B:'static>() -> alist<isize, B> {
57 fn eq_int(a: isize, b: isize) -> bool { a == b }
60 data: box RefCell::new(Vec::new()),