Acme-Color-Rust

 view release on metacpan or  search on metacpan

ffi/src/lib.rs  view on Meta::CPAN


    fn get_green(&self) -> u8 {
        self.green
    }

    fn get_blue(&self) -> u8 {
        self.blue
    }
}

thread_local!(
  static COUNTER: Cell<u32> = Cell::new(0);
  static STORE: RefCell<HashMap<u32, Color>> = RefCell::new(HashMap::new())
);

#[no_mangle]
pub extern "C" fn color_new(name: *const c_char, red: u8, green: u8, blue: u8) -> u32 {
    let name = unsafe { CStr::from_ptr(name) };
    let color = Color::new(name.to_str().unwrap(), red, green, blue);

    let index = COUNTER.with(|it| {

ffi/src/lib.rs  view on Meta::CPAN

    STORE.with(|it| {
        let mut it = it.borrow_mut();
        it.insert(index, color);
    });

    index
}

#[no_mangle]
pub extern "C" fn color_name(index: u32) -> *const c_char {
    thread_local!(
        static KEEP: RefCell<Option<CString>> = RefCell::new(None);
    );

    let name = STORE.with(|it| {
        let it = it.borrow();
        let color = it.get(&index).unwrap();
        color.get_name()
    });

    let name = CString::new(name).unwrap();



( run in 1.671 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )