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 #![allow(unknown_features)]
12 #![feature(box_syntax)]
14 use std::cell::RefCell;
16 pub struct Entry<A,B> {
21 pub struct alist<A,B> {
22 eq_fn: extern "Rust" fn(A,A) -> bool,
23 data: Box<RefCell<Vec<Entry<A,B>>>>,
26 pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
27 let mut data = lst.data.borrow_mut();
28 (*data).push(Entry{key:k, value:v});
31 pub fn alist_get<A:Clone + 'static,
36 let eq_fn = lst.eq_fn;
37 let data = lst.data.borrow();
38 for entry in &(*data) {
39 if eq_fn(entry.key.clone(), k.clone()) {
40 return entry.value.clone();
47 pub fn new_int_alist<B:'static>() -> alist<isize, B> {
48 fn eq_int(a: isize, b: isize) -> bool { a == b }
51 data: box RefCell::new(Vec::new()),
56 pub fn new_int_alist_2<B:'static>() -> alist<isize, B> {
58 fn eq_int(a: isize, b: isize) -> bool { a == b }
61 data: box RefCell::new(Vec::new()),