presses: Move press handling to Rust
This fixes some rendering things which would happen with multiple state-sharing buttons. It also removes some interfaces exposing rows, views, layouts, and buttons, bringing the code closer to removing them from the FFI entirely.
This commit is contained in:
23
src/util.rs
23
src/util.rs
@ -2,6 +2,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use std::hash::{ Hash, Hasher };
|
||||
use std::iter::FromIterator;
|
||||
|
||||
@ -111,7 +112,7 @@ pub mod c {
|
||||
|
||||
fn clone_owned(&self) -> T {
|
||||
let rc = self.clone_ref();
|
||||
let r = rc.borrow();
|
||||
let r = RefCell::borrow(&rc);
|
||||
r.to_owned()
|
||||
}
|
||||
}
|
||||
@ -133,7 +134,13 @@ pub fn hash_map_map<K, V, F, K1, V1>(map: HashMap<K, V>, mut f: F)
|
||||
}
|
||||
|
||||
/// Compares pointers but not internal values of Rc
|
||||
pub struct Pointer<T>(Rc<T>);
|
||||
pub struct Pointer<T>(pub Rc<T>);
|
||||
|
||||
impl<T> Pointer<T> {
|
||||
pub fn new(value: T) -> Self {
|
||||
Pointer(Rc::new(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Hash for Pointer<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
@ -149,6 +156,18 @@ impl<T> PartialEq for Pointer<T> {
|
||||
|
||||
impl<T> Eq for Pointer<T> {}
|
||||
|
||||
impl<T> Clone for Pointer<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Pointer(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Borrow<Rc<T>> for Pointer<T> {
|
||||
fn borrow(&self) -> &Rc<T> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user