Incorporate clippy suggestions
This commit is contained in:
parent
38d7a0e974
commit
e70ba3a752
5 changed files with 15 additions and 18 deletions
|
@ -11,8 +11,7 @@ lvgl-sys = { path = "../lvgl-sys" }
|
||||||
embedded-graphics = "0.6"
|
embedded-graphics = "0.6"
|
||||||
embedded-graphics-simulator = "0.2.0"
|
embedded-graphics-simulator = "0.2.0"
|
||||||
heapless = "0.5.5"
|
heapless = "0.5.5"
|
||||||
cstr_core = { version = "0.2.0" }
|
cstr_core = { version = "0.2.0", features = ["alloc"] }
|
||||||
typenum = "1.12.0"
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "demo"
|
name = "demo"
|
||||||
|
|
|
@ -63,7 +63,6 @@ fn main() -> Result<(), LvError> {
|
||||||
|
|
||||||
let mut t: heapless::String<heapless::consts::U8> = heapless::String::from("test");
|
let mut t: heapless::String<heapless::consts::U8> = heapless::String::from("test");
|
||||||
t.push('\0').unwrap();
|
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::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::CStr::from_bytes_with_nul("test\0".as_bytes()).unwrap()).unwrap();
|
||||||
set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap();
|
set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap();
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl LvFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_method(&self) -> bool {
|
pub fn is_method(&self) -> bool {
|
||||||
if self.args.len() > 0 {
|
if !self.args.is_empty() {
|
||||||
let first_arg = &self.args[0];
|
let first_arg = &self.args[0];
|
||||||
return first_arg.typ.literal_name.contains("lv_obj_t");
|
return first_arg.typ.literal_name.contains("lv_obj_t");
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,7 @@ impl CodeGen {
|
||||||
&self.widgets
|
&self.widgets
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_widgets(functions: &Vec<LvFunc>) -> CGResult<Vec<LvWidget>> {
|
fn extract_widgets(functions: &[LvFunc]) -> CGResult<Vec<LvWidget>> {
|
||||||
let widget_names = Self::get_widget_names(functions);
|
let widget_names = Self::get_widget_names(functions);
|
||||||
|
|
||||||
let widgets = functions.iter().fold(HashMap::new(), |mut ws, f| {
|
let widgets = functions.iter().fold(HashMap::new(), |mut ws, f| {
|
||||||
|
@ -395,25 +395,25 @@ impl CodeGen {
|
||||||
ws
|
ws
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(widgets.values().map(|v| v.clone()).collect())
|
Ok(widgets.values().cloned().collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_widget_names(functions: &Vec<LvFunc>) -> Vec<String> {
|
fn get_widget_names(functions: &[LvFunc]) -> Vec<String> {
|
||||||
let reg = format!("^{}([^_]+)_create$", LIB_PREFIX);
|
let reg = format!("^{}([^_]+)_create$", LIB_PREFIX);
|
||||||
let create_func = Regex::new(reg.as_str()).unwrap();
|
let create_func = Regex::new(reg.as_str()).unwrap();
|
||||||
|
|
||||||
functions
|
functions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|e| create_func.is_match(e.name.as_str()) && e.args.len() == 2)
|
.filter(|e| create_func.is_match(e.name.as_str()) && e.args.len() == 2)
|
||||||
.filter_map(|f| {
|
.map(|f| {
|
||||||
Some(String::from(
|
String::from(
|
||||||
create_func
|
create_func
|
||||||
.captures(f.name.as_str())
|
.captures(f.name.as_str())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get(1)
|
.get(1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str(),
|
.as_str(),
|
||||||
))
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ embedded-graphics = "0.6.2"
|
||||||
cstr_core = { version = "0.2.0" }
|
cstr_core = { version = "0.2.0" }
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
heapless = "0.5.5"
|
heapless = "0.5.5"
|
||||||
typenum = "1.12.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
quote = "1.0.7"
|
quote = "1.0.7"
|
||||||
|
|
|
@ -5,16 +5,16 @@ use core::ptr;
|
||||||
use core::ptr::NonNull;
|
use core::ptr::NonNull;
|
||||||
|
|
||||||
/// Places `T` into LVGL memory.
|
/// Places `T` into LVGL memory.
|
||||||
pub struct Box<T: Sized>(NonNull<T>);
|
pub struct Box<T>(NonNull<T>);
|
||||||
|
|
||||||
impl<T: Sized> Box<T> {
|
impl<T> Box<T> {
|
||||||
pub fn new(inner: T) -> LvResult<Box<T>> {
|
pub fn new(inner: T) -> LvResult<Box<T>> {
|
||||||
let layout = mem::size_of::<T>();
|
let layout = mem::size_of::<T>();
|
||||||
let inner = unsafe {
|
let inner = unsafe {
|
||||||
let ptr = lvgl_sys::lv_mem_alloc(layout as lvgl_sys::size_t) as *mut T;
|
let ptr = lvgl_sys::lv_mem_alloc(layout as lvgl_sys::size_t) as *mut T;
|
||||||
match NonNull::new(ptr) {
|
match NonNull::new(ptr) {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
// Place value in new mem
|
// Move `T` to LVGL managed memory
|
||||||
ptr::write(ptr, inner);
|
ptr::write(ptr, inner);
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl<T: Sized> Box<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Sized> Drop for Box<T> {
|
impl<T> Drop for Box<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
lvgl_sys::lv_mem_free(self.0.as_ptr() as *const cty::c_void);
|
lvgl_sys::lv_mem_free(self.0.as_ptr() as *const cty::c_void);
|
||||||
|
@ -38,7 +38,7 @@ impl<T: Sized> Drop for Box<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Sized> Deref for Box<T> {
|
impl<T> Deref for Box<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
fn deref(&self) -> &T {
|
||||||
|
@ -46,13 +46,13 @@ impl<T: Sized> Deref for Box<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Sized> DerefMut for Box<T> {
|
impl<T> DerefMut for Box<T> {
|
||||||
fn deref_mut(&mut self) -> &mut T {
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
unsafe { self.0.as_mut() }
|
unsafe { self.0.as_mut() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Sized> AsMut<T> for Box<T> {
|
impl<T> AsMut<T> for Box<T> {
|
||||||
fn as_mut(&mut self) -> &mut T {
|
fn as_mut(&mut self) -> &mut T {
|
||||||
unsafe { self.0.as_mut() }
|
unsafe { self.0.as_mut() }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue