cleanup: Unbox View and Row

They are no longer referenced anywhere in C, so it's safe to let Rust memory management deal with them.
This commit is contained in:
Dorota Czaplejewicz
2019-12-07 15:50:21 +00:00
parent 1c4d027af5
commit 36362291ef
2 changed files with 19 additions and 16 deletions

View File

@ -405,7 +405,7 @@ impl Layout {
let views = HashMap::from_iter( let views = HashMap::from_iter(
self.views.iter().map(|(name, view)| {( self.views.iter().map(|(name, view)| {(
name.clone(), name.clone(),
Box::new(::layout::View { ::layout::View {
bounds: ::layout::c::Bounds { bounds: ::layout::c::Bounds {
x: self.bounds.x, x: self.bounds.x,
y: self.bounds.y, y: self.bounds.y,
@ -413,7 +413,7 @@ impl Layout {
height: self.bounds.height, height: self.bounds.height,
}, },
rows: view.iter().map(|row| { rows: view.iter().map(|row| {
Box::new(::layout::Row { ::layout::Row {
angle: 0, angle: 0,
bounds: None, bounds: None,
buttons: row.split_ascii_whitespace().map(|name| { buttons: row.split_ascii_whitespace().map(|name| {
@ -427,9 +427,9 @@ impl Layout {
&mut warning_handler, &mut warning_handler,
)) ))
}).collect(), }).collect(),
}) }
}).collect(), }).collect(),
}) }
)}) )})
); );

View File

@ -74,7 +74,7 @@ pub mod c {
/// Defined in eek-types.h /// Defined in eek-types.h
#[repr(C)] #[repr(C)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq)]
pub struct Bounds { pub struct Bounds {
pub x: f64, pub x: f64,
pub y: f64, pub y: f64,
@ -570,7 +570,7 @@ pub struct Spacing {
pub struct View { pub struct View {
/// Position relative to keyboard origin /// Position relative to keyboard origin
pub bounds: c::Bounds, pub bounds: c::Bounds,
pub rows: Vec<Box<Row>>, pub rows: Vec<Row>,
} }
impl View { impl View {
@ -665,7 +665,7 @@ pub struct Layout {
// Views own the actual buttons which have state // Views own the actual buttons which have state
// Maybe they should own UI only, // Maybe they should own UI only,
// and keys should be owned by a dedicated non-UI-State? // and keys should be owned by a dedicated non-UI-State?
pub views: HashMap<String, Box<View>>, pub views: HashMap<String, View>,
// Non-UI stuff // Non-UI stuff
/// xkb keymap applicable to the contained keys. Unchangeable /// xkb keymap applicable to the contained keys. Unchangeable
@ -684,7 +684,7 @@ pub struct Layout {
/// A builder structure for picking up layout data from storage /// A builder structure for picking up layout data from storage
pub struct LayoutData { pub struct LayoutData {
pub views: HashMap<String, Box<View>>, pub views: HashMap<String, View>,
pub keymap_str: CString, pub keymap_str: CString,
} }
@ -706,7 +706,7 @@ impl Layout {
} }
} }
pub fn get_current_view(&self) -> &Box<View> { pub fn get_current_view(&self) -> &View {
self.views.get(&self.current_view).expect("Selected nonexistent view") self.views.get(&self.current_view).expect("Selected nonexistent view")
} }
@ -815,7 +815,7 @@ impl Layout {
mod procedures { mod procedures {
use super::*; use super::*;
type Path<'v> = (&'v Box<Row>, &'v Box<Button>); type Path<'v> = (&'v Row, &'v Box<Button>);
/// Finds all `(row, button)` paths that refer to the specified key `state` /// Finds all `(row, button)` paths that refer to the specified key `state`
pub fn find_key_paths<'v, 's>( pub fn find_key_paths<'v, 's>(
@ -868,12 +868,15 @@ mod procedures {
let button = make_button_with_state("1".into(), state); let button = make_button_with_state("1".into(), state);
let button_ptr = as_ptr(&button); let button_ptr = as_ptr(&button);
let row = Box::new(Row { let row_bounds = Some(c::Bounds {
x: 0.1, y: 2.3,
width: 4.5, height: 6.7,
});
let row = Row {
buttons: vec!(button), buttons: vec!(button),
angle: 0, angle: 0,
bounds: None bounds: row_bounds.clone(),
}); };
let row_ptr = as_ptr(&row);
let view = View { let view = View {
bounds: c::Bounds { bounds: c::Bounds {
@ -885,10 +888,10 @@ mod procedures {
assert_eq!( assert_eq!(
find_key_paths(&view, &state_clone.clone()).iter() find_key_paths(&view, &state_clone.clone()).iter()
.map(|(row, button)| { (as_ptr(row), as_ptr(button)) }) .map(|(row, button)| { (row.bounds.clone(), as_ptr(button)) })
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
vec!( vec!(
(row_ptr, button_ptr) (row_bounds, button_ptr)
) )
); );