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:
parent
65de6d177d
commit
2821564b5d
|
@ -39,7 +39,7 @@ cc = "1.0.25"
|
|||
[dependencies]
|
||||
lazy_static = "1.2"
|
||||
libc = "0.2.0"
|
||||
log = "0.3"
|
||||
log = "0.4"
|
||||
simflash = { path = "../simflash" }
|
||||
|
||||
# Optimize some, even when building for debugging, otherwise the tests
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
//! HAL api for MyNewt applications
|
||||
|
||||
use simflash::{Result, Flash, FlashPtr};
|
||||
use lazy_static::lazy_static;
|
||||
use libc;
|
||||
use log::LogLevel;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::ops::Deref;
|
||||
use log::{Level, log_enabled, warn};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
mem,
|
||||
ops::Deref,
|
||||
slice,
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
/// A FlashMap maintain a table of [device_id -> Flash trait]
|
||||
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.
|
||||
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();
|
||||
flash_params.insert(dev_id, FlashParams {
|
||||
align: dev.align() as u8,
|
||||
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();
|
||||
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) {
|
||||
|
@ -117,10 +120,10 @@ fn map_err(err: Result<()>) -> libc::c_int {
|
|||
#[no_mangle]
|
||||
pub extern fn sim_log_enabled(level: libc::c_int) -> libc::c_int {
|
||||
let res = match level {
|
||||
1 => log_enabled!(LogLevel::Error),
|
||||
2 => log_enabled!(LogLevel::Warn),
|
||||
3 => log_enabled!(LogLevel::Info),
|
||||
4 => log_enabled!(LogLevel::Trace),
|
||||
1 => log_enabled!(Level::Error),
|
||||
2 => log_enabled!(Level::Warn),
|
||||
3 => log_enabled!(Level::Info),
|
||||
4 => log_enabled!(Level::Trace),
|
||||
_ => false,
|
||||
};
|
||||
if res {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::area::AreaDesc;
|
||||
use simflash::SimFlashMap;
|
||||
use lazy_static::lazy_static;
|
||||
use libc;
|
||||
use crate::api;
|
||||
use std::sync::Mutex;
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
#[macro_use] extern crate lazy_static;
|
||||
extern crate libc;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate simflash;
|
||||
|
||||
mod area;
|
||||
pub mod c;
|
||||
|
||||
|
|
Loading…
Reference in New Issue