Commit ea25c41a authored by David Brown's avatar David Brown Committed by David Brown
Browse files

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: default avatarDavid Brown <david.brown@linaro.org>
parent afabfcfe
Loading
Loading
Loading
Loading
+1 −1
Changes for sim/simflash/Cargo.toml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,4 +7,4 @@ edition = "2018"
[dependencies]
error-chain = "0.12.0"
rand = "0.3.0"
log = "0.3"
log = "0.4"
+17 −13
Changes for sim/simflash/src/lib.rs: 17 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -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 @@ error_chain! {
}

pub struct FlashPtr {
   pub ptr: *mut Flash,
   pub ptr: *mut dyn Flash,
}
unsafe impl Send for FlashPtr {}

@@ -49,7 +53,7 @@ pub trait Flash {

    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 @@ impl Flash for SimFlash {
    }

    /// 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 @@ mod test {
        }
    }

    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();