Commit 10b5de13 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Idiomize for Rust 2018

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 29b0b5ec
Loading
Loading
Loading
Loading
+23 −27
Changes for sim/src/lib.rs: 23 added lines, 27 removed lines.
Original line number Diff line number Diff line
#[macro_use] extern crate log;
extern crate ring;
extern crate aes_ctr;
extern crate base64;
extern crate env_logger;
extern crate docopt;
extern crate libc;
extern crate pem;
extern crate rand;
#[macro_use] extern crate serde_derive;
extern crate serde;
extern crate simflash;
extern crate untrusted;
extern crate mcuboot_sys;

use docopt::Docopt;
use rand::{Rng, SeedableRng, XorShiftRng};
use rand::distributions::{IndependentSample, Range};
use std::fmt;
use std::mem;
use std::process;
use std::slice;
use aes_ctr::Aes128Ctr;
use aes_ctr::stream_cipher::generic_array::GenericArray;
use aes_ctr::stream_cipher::{NewFixStreamCipher, StreamCipherCore};
use log::{info, warn, error};
use rand::{
    distributions::{IndependentSample, Range},
    Rng, SeedableRng, XorShiftRng,
};
use std::{
    fmt,
    mem,
    process,
    slice,
};
use aes_ctr::{
    Aes128Ctr,
    stream_cipher::{
        generic_array::GenericArray,
        NewFixStreamCipher,
        StreamCipherCore,
    },
};
use serde_derive::Deserialize;

mod caps;
mod tlv;
@@ -73,7 +69,7 @@ pub static ALL_DEVICES: &'static [DeviceName] = &[
];

impl fmt::Display for DeviceName {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let name = match *self {
            DeviceName::Stm32f4 => "stm32f4",
            DeviceName::K64f => "k64f",
@@ -93,7 +89,7 @@ struct AlignArgVisitor;
impl<'de> serde::de::Visitor<'de> for AlignArgVisitor {
    type Value = AlignArg;

    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str("1, 2, 4 or 8")
    }

@@ -1033,7 +1029,7 @@ fn try_random_fails(flashmap: &SimFlashMap, images: &Images,

/// Show the flash layout.
#[allow(dead_code)]
fn show_flash(flash: &Flash) {
fn show_flash(flash: &dyn Flash) {
    println!("---- Flash configuration ----");
    for sector in flash.sector_iter() {
        println!("    {:3}: 0x{:08x}, 0x{:08x}",
+2 −2
Changes for sim/src/main.rs: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
extern crate env_logger;
use env_logger;

extern crate bootsim;
use bootsim;

fn main() {
    env_logger::init().unwrap();
−2
Changes for sim/tests/core.rs: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@
//!
//! Run the existing testsuite as a Rust unit test.

extern crate bootsim;

use bootsim::{Run, testlog};

macro_rules! sim_test {