sim: mcuboot-sys: More idiomatic Rust 2018

Apply the changes suggested by

    cargo fix --edition-idioms

and cleanup the results a bit.  Eliminate `macro_use` extern crates.

Signed-off-by: David Brown <david.brown@linaro.org>
This commit is contained in:
David Brown 2019-01-02 11:42:39 -07:00 committed by David Brown
parent 65de6d177d
commit 2821564b5d
4 changed files with 18 additions and 19 deletions

View File

@ -39,7 +39,7 @@ cc = "1.0.25"
[dependencies] [dependencies]
lazy_static = "1.2" lazy_static = "1.2"
libc = "0.2.0" libc = "0.2.0"
log = "0.3" log = "0.4"
simflash = { path = "../simflash" } simflash = { path = "../simflash" }
# Optimize some, even when building for debugging, otherwise the tests # Optimize some, even when building for debugging, otherwise the tests

View File

@ -1,13 +1,16 @@
//! HAL api for MyNewt applications //! HAL api for MyNewt applications
use simflash::{Result, Flash, FlashPtr}; use simflash::{Result, Flash, FlashPtr};
use lazy_static::lazy_static;
use libc; use libc;
use log::LogLevel; use log::{Level, log_enabled, warn};
use std::mem; use std::{
use std::slice; collections::HashMap,
use std::collections::HashMap; mem,
use std::sync::Mutex; ops::Deref,
use std::ops::Deref; slice,
sync::Mutex,
};
/// A FlashMap maintain a table of [device_id -> Flash trait] /// A FlashMap maintain a table of [device_id -> Flash trait]
pub type FlashMap = HashMap<u8, FlashPtr>; pub type FlashMap = HashMap<u8, FlashPtr>;
@ -30,16 +33,16 @@ lazy_static! {
} }
// Set the flash device to be used by the simulation. The pointer is unsafely stashed away. // Set the flash device to be used by the simulation. The pointer is unsafely stashed away.
pub unsafe fn set_flash(dev_id: u8, dev: &mut Flash) { pub unsafe fn set_flash(dev_id: u8, dev: &mut dyn Flash) {
let mut flash_params = FLASH_PARAMS.lock().unwrap(); let mut flash_params = FLASH_PARAMS.lock().unwrap();
flash_params.insert(dev_id, FlashParams { flash_params.insert(dev_id, FlashParams {
align: dev.align() as u8, align: dev.align() as u8,
erased_val: dev.erased_val(), erased_val: dev.erased_val(),
}); });
let dev: &'static mut Flash = mem::transmute(dev); let dev: &'static mut dyn Flash = mem::transmute(dev);
let mut flash = FLASH.lock().unwrap(); let mut flash = FLASH.lock().unwrap();
flash.insert(dev_id, FlashPtr{ptr: dev as *mut Flash}); flash.insert(dev_id, FlashPtr{ptr: dev as *mut dyn Flash});
} }
pub unsafe fn clear_flash(dev_id: u8) { pub unsafe fn clear_flash(dev_id: u8) {
@ -117,10 +120,10 @@ fn map_err(err: Result<()>) -> libc::c_int {
#[no_mangle] #[no_mangle]
pub extern fn sim_log_enabled(level: libc::c_int) -> libc::c_int { pub extern fn sim_log_enabled(level: libc::c_int) -> libc::c_int {
let res = match level { let res = match level {
1 => log_enabled!(LogLevel::Error), 1 => log_enabled!(Level::Error),
2 => log_enabled!(LogLevel::Warn), 2 => log_enabled!(Level::Warn),
3 => log_enabled!(LogLevel::Info), 3 => log_enabled!(Level::Info),
4 => log_enabled!(LogLevel::Trace), 4 => log_enabled!(Level::Trace),
_ => false, _ => false,
}; };
if res { if res {

View File

@ -2,6 +2,7 @@
use crate::area::AreaDesc; use crate::area::AreaDesc;
use simflash::SimFlashMap; use simflash::SimFlashMap;
use lazy_static::lazy_static;
use libc; use libc;
use crate::api; use crate::api;
use std::sync::Mutex; use std::sync::Mutex;

View File

@ -1,8 +1,3 @@
#[macro_use] extern crate lazy_static;
extern crate libc;
#[macro_use] extern crate log;
extern crate simflash;
mod area; mod area;
pub mod c; pub mod c;