sim: simflash: Rust 2018 idiom updates
Apply the changes suggested by
cargo fix --edition-idioms
as well as a bit of cleanup of the results. The result should be more
idiomatic Rust 2018 and a good starting point moving forward.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/simflash/Cargo.toml b/sim/simflash/Cargo.toml
index d65dc8a..3d5e89a 100644
--- a/sim/simflash/Cargo.toml
+++ b/sim/simflash/Cargo.toml
@@ -7,4 +7,4 @@
[dependencies]
error-chain = "0.12.0"
rand = "0.3.0"
-log = "0.3"
+log = "0.4"
diff --git a/sim/simflash/src/lib.rs b/sim/simflash/src/lib.rs
index 26f8187..cd074c9 100644
--- a/sim/simflash/src/lib.rs
+++ b/sim/simflash/src/lib.rs
@@ -3,19 +3,23 @@
//! This module is capable of simulating the type of NOR flash commonly used in microcontrollers.
//! These generally can be written as individual bytes, but must be erased in larger units.
-#[macro_use] extern crate log;
#[macro_use] extern crate error_chain;
-extern crate rand;
mod pdump;
-use rand::distributions::{IndependentSample, Range};
-use std::fs::File;
-use std::io::Write;
-use std::iter::Enumerate;
-use std::path::Path;
-use std::slice;
-use std::collections::HashMap;
use crate::pdump::HexDump;
+use log::info;
+use rand::{
+ self,
+ distributions::{IndependentSample, Range},
+};
+use std::{
+ collections::HashMap,
+ fs::File,
+ io::Write,
+ iter::Enumerate,
+ path::Path,
+ slice,
+};
error_chain! {
errors {
@@ -35,7 +39,7 @@
}
pub struct FlashPtr {
- pub ptr: *mut Flash,
+ pub ptr: *mut dyn Flash,
}
unsafe impl Send for FlashPtr {}
@@ -49,7 +53,7 @@
fn set_verify_writes(&mut self, enable: bool);
- fn sector_iter(&self) -> SectorIter;
+ fn sector_iter(&self) -> SectorIter<'_>;
fn device_size(&self) -> usize;
fn align(&self) -> usize;
@@ -237,7 +241,7 @@
}
/// An iterator over each sector in the device.
- fn sector_iter(&self) -> SectorIter {
+ fn sector_iter(&self) -> SectorIter<'_> {
SectorIter {
iter: self.sectors.iter().enumerate(),
base: 0,
@@ -310,7 +314,7 @@
}
}
- fn test_device(flash: &mut Flash, erased_val: u8) {
+ fn test_device(flash: &mut dyn Flash, erased_val: u8) {
let sectors: Vec<Sector> = flash.sector_iter().collect();
flash.erase(0, sectors[0].size).unwrap();