Incorporate clippy suggestions

This commit is contained in:
Rafael Caricio 2020-06-17 08:38:35 +02:00 committed by Rafael Carício
parent 38d7a0e974
commit e70ba3a752
5 changed files with 15 additions and 18 deletions

View file

@ -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"

View file

@ -63,7 +63,6 @@ fn main() -> Result<(), LvError> {
let mut t: heapless::String<heapless::consts::U8> = 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();

View file

@ -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<LvFunc>) -> CGResult<Vec<LvWidget>> {
fn extract_widgets(functions: &[LvFunc]) -> CGResult<Vec<LvWidget>> {
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<LvFunc>) -> Vec<String> {
fn get_widget_names(functions: &[LvFunc]) -> Vec<String> {
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::<Vec<_>>()
}

View file

@ -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"

View file

@ -5,16 +5,16 @@ use core::ptr;
use core::ptr::NonNull;
/// 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>> {
let layout = mem::size_of::<T>();
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<T: Sized> Box<T> {
}
}
impl<T: Sized> Drop for Box<T> {
impl<T> Drop for Box<T> {
fn drop(&mut self) {
unsafe {
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;
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 {
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 {
unsafe { self.0.as_mut() }
}