Implement Clone for Style

This commit is contained in:
Sam Jones 2022-03-22 11:49:26 +00:00 committed by Rafael Carício
parent 0a5b5a0416
commit 763b78e45d
2 changed files with 20 additions and 0 deletions

View file

@ -7,6 +7,7 @@ pub enum Themes {
Pretty, Pretty,
} }
#[derive(Clone)]
pub struct Style { pub struct Style {
pub(crate) raw: Box<lvgl_sys::lv_style_t>, pub(crate) raw: Box<lvgl_sys::lv_style_t>,
} }

View file

@ -69,6 +69,12 @@ impl<T> AsMut<T> for Box<T> {
} }
} }
impl<T: Clone> Clone for Box<T> {
fn clone(&self) -> Self {
unsafe { Self::new(self.0.as_ref().clone()) }
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
@ -136,6 +142,19 @@ mod test {
assert_eq!(initial_mem_info.free_size, final_info.free_size) assert_eq!(initial_mem_info.free_size, final_info.free_size)
} }
#[test]
fn clone_object_in_lv_mem() {
crate::lvgl_init();
let v1 = Box::new(5);
let v2 = v1.clone();
// Ensure that the two objects have identical values.
assert_eq!(*v1, *v2);
// They should have different memory addresses, however.
assert_ne!(v1.into_raw() as usize, v2.into_raw() as usize);
}
fn mem_info() -> lvgl_sys::lv_mem_monitor_t { fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
let mut info = lvgl_sys::lv_mem_monitor_t { let mut info = lvgl_sys::lv_mem_monitor_t {
total_size: 0, total_size: 0,