diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 9861468..5e116c8 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -11,8 +11,7 @@ lvgl-sys = { path = "../lvgl-sys" } embedded-graphics = "0.6" embedded-graphics-simulator = "0.2.0" heapless = "0.5.5" -cstr_core = { version = "0.2.0" } -typenum = "1.12.0" +cstr_core = { version = "0.2.0", features = ["alloc"] } [[example]] name = "demo" diff --git a/examples/demo.rs b/examples/demo.rs index 6b2533b..279b657 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -63,7 +63,6 @@ fn main() -> Result<(), LvError> { let mut t: heapless::String = heapless::String::from("test"); t.push('\0').unwrap(); - CStr::from_bytes_with_nul_unchecked(); set_text(CStr::from_bytes_with_nul(t.as_bytes()).unwrap()).unwrap(); set_text(cstr_core::CStr::from_bytes_with_nul("test\0".as_bytes()).unwrap()).unwrap(); set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap(); diff --git a/lvgl-codegen/src/lib.rs b/lvgl-codegen/src/lib.rs index 73917f1..b6b8132 100644 --- a/lvgl-codegen/src/lib.rs +++ b/lvgl-codegen/src/lib.rs @@ -79,7 +79,7 @@ impl LvFunc { } pub fn is_method(&self) -> bool { - if self.args.len() > 0 { + if !self.args.is_empty() { let first_arg = &self.args[0]; return first_arg.typ.literal_name.contains("lv_obj_t"); } @@ -374,7 +374,7 @@ impl CodeGen { &self.widgets } - fn extract_widgets(functions: &Vec) -> CGResult> { + fn extract_widgets(functions: &[LvFunc]) -> CGResult> { let widget_names = Self::get_widget_names(functions); let widgets = functions.iter().fold(HashMap::new(), |mut ws, f| { @@ -395,25 +395,25 @@ impl CodeGen { ws }); - Ok(widgets.values().map(|v| v.clone()).collect()) + Ok(widgets.values().cloned().collect()) } - fn get_widget_names(functions: &Vec) -> Vec { + fn get_widget_names(functions: &[LvFunc]) -> Vec { let reg = format!("^{}([^_]+)_create$", LIB_PREFIX); let create_func = Regex::new(reg.as_str()).unwrap(); functions .iter() .filter(|e| create_func.is_match(e.name.as_str()) && e.args.len() == 2) - .filter_map(|f| { - Some(String::from( + .map(|f| { + String::from( create_func .captures(f.name.as_str()) .unwrap() .get(1) .unwrap() .as_str(), - )) + ) }) .collect::>() } diff --git a/lvgl/Cargo.toml b/lvgl/Cargo.toml index bd29e1b..6d2e0a5 100644 --- a/lvgl/Cargo.toml +++ b/lvgl/Cargo.toml @@ -18,7 +18,6 @@ embedded-graphics = "0.6.2" cstr_core = { version = "0.2.0" } bitflags = "1.2.1" heapless = "0.5.5" -typenum = "1.12.0" [build-dependencies] quote = "1.0.7" diff --git a/lvgl/src/mem.rs b/lvgl/src/mem.rs index 7f1bae9..984d8c8 100644 --- a/lvgl/src/mem.rs +++ b/lvgl/src/mem.rs @@ -5,16 +5,16 @@ use core::ptr; use core::ptr::NonNull; /// Places `T` into LVGL memory. -pub struct Box(NonNull); +pub struct Box(NonNull); -impl Box { +impl Box { pub fn new(inner: T) -> LvResult> { let layout = mem::size_of::(); let inner = unsafe { let ptr = lvgl_sys::lv_mem_alloc(layout as lvgl_sys::size_t) as *mut T; match NonNull::new(ptr) { Some(v) => { - // Place value in new mem + // Move `T` to LVGL managed memory ptr::write(ptr, inner); Ok(v) } @@ -30,7 +30,7 @@ impl Box { } } -impl Drop for Box { +impl Drop for Box { fn drop(&mut self) { unsafe { lvgl_sys::lv_mem_free(self.0.as_ptr() as *const cty::c_void); @@ -38,7 +38,7 @@ impl Drop for Box { } } -impl Deref for Box { +impl Deref for Box { type Target = T; fn deref(&self) -> &T { @@ -46,13 +46,13 @@ impl Deref for Box { } } -impl DerefMut for Box { +impl DerefMut for Box { fn deref_mut(&mut self) -> &mut T { unsafe { self.0.as_mut() } } } -impl AsMut for Box { +impl AsMut for Box { fn as_mut(&mut self) -> &mut T { unsafe { self.0.as_mut() } }