Skip to content

Commit

Permalink
Reformat with use_small_heuristics = "Max"
Browse files Browse the repository at this point in the history
  • Loading branch information
valff committed Dec 24, 2019
1 parent a2c83af commit f572e58
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 278 deletions.
12 changes: 2 additions & 10 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@ impl Config {
}

fn check_heap(&self) -> Result<()> {
let Self {
heap: Heap { size, pools },
..
} = self;
let Self { heap: Heap { size, pools }, .. } = self;
let used: u32 = pools.iter().map(|pool| pool.block * pool.capacity).sum();
if used != *size {
bail!(
"{}: `heap.pools` adds up to {}, but `heap.size = {}",
CONFIG_NAME,
used,
size
);
bail!("{}: `heap.pools` adds up to {}, but `heap.size = {}", CONFIG_NAME, used, size);
}
Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ format_strings = true
merge_imports = true
newline_style = "Unix"
overflow_delimited_expr = true
reorder_impl_items = true
unstable_features = true
use_field_init_shorthand = true
use_small_heuristics = "Max"
version = "Two"
5 changes: 2 additions & 3 deletions src/bin/drone-ld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ fn main() {
let config = Config::read_from_current_dir()?;
let script = Registry::new()?.layout_ld(&config)?;
let signals = register_signals()?;
let linker = linker_command(script.as_ref(), &args, &[
"--defsym=_section_size_unknown=0".into(),
])?;
let linker =
linker_command(script.as_ref(), &args, &["--defsym=_section_size_unknown=0".into()])?;
block_with_signals(&signals, true, || run_command(linker))?;
let size = size_command(&output)?;
let syms = block_with_signals(&signals, true, || run_size(size))?
Expand Down
5 changes: 1 addition & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ fn parse_color(src: &str) -> Result<ColorChoice, Error> {
"always" => ColorChoice::Always,
"never" => ColorChoice::Never,
"auto" => ColorChoice::Auto,
_ => bail!(
"argument for --color must be auto, always, or never, but found `{}`",
src
),
_ => bail!("argument for --color must be auto, always, or never, but found `{}`", src),
})
}
96 changes: 48 additions & 48 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,54 +299,54 @@ impl Device {
Self::Nrf52811 => (crates::Bindings::Nrf, "nrf52811", &[]),
Self::Nrf52832 => (crates::Bindings::Nrf, "nrf52832", &[]),
Self::Nrf52840 => (crates::Bindings::Nrf, "nrf52840", &[]),
Self::Stm32F100 => (crates::Bindings::Stm32, "stm32f100", &[
"dma", "gpio", "spi", "tim",
]),
Self::Stm32F101 => (crates::Bindings::Stm32, "stm32f101", &[
"dma", "gpio", "spi", "tim",
]),
Self::Stm32F102 => (crates::Bindings::Stm32, "stm32f102", &[
"dma", "gpio", "spi", "tim",
]),
Self::Stm32F103 => (crates::Bindings::Stm32, "stm32f103", &[
"dma", "gpio", "spi", "tim",
]),
Self::Stm32F107 => (crates::Bindings::Stm32, "stm32f107", &[
"dma", "gpio", "spi", "tim",
]),
Self::Stm32F401 => (crates::Bindings::Stm32, "stm32f401", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F405 => (crates::Bindings::Stm32, "stm32f405", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F407 => (crates::Bindings::Stm32, "stm32f407", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F410 => (crates::Bindings::Stm32, "stm32f410", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F411 => (crates::Bindings::Stm32, "stm32f411", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F412 => (crates::Bindings::Stm32, "stm32f412", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F413 => (crates::Bindings::Stm32, "stm32f413", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F427 => (crates::Bindings::Stm32, "stm32f427", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F429 => (crates::Bindings::Stm32, "stm32f429", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F446 => (crates::Bindings::Stm32, "stm32f446", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F469 => (crates::Bindings::Stm32, "stm32f469", &[
"adc", "dma", "exti", "gpio", "tim",
]),
Self::Stm32F100 => {
(crates::Bindings::Stm32, "stm32f100", &["dma", "gpio", "spi", "tim"])
}
Self::Stm32F101 => {
(crates::Bindings::Stm32, "stm32f101", &["dma", "gpio", "spi", "tim"])
}
Self::Stm32F102 => {
(crates::Bindings::Stm32, "stm32f102", &["dma", "gpio", "spi", "tim"])
}
Self::Stm32F103 => {
(crates::Bindings::Stm32, "stm32f103", &["dma", "gpio", "spi", "tim"])
}
Self::Stm32F107 => {
(crates::Bindings::Stm32, "stm32f107", &["dma", "gpio", "spi", "tim"])
}
Self::Stm32F401 => {
(crates::Bindings::Stm32, "stm32f401", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F405 => {
(crates::Bindings::Stm32, "stm32f405", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F407 => {
(crates::Bindings::Stm32, "stm32f407", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F410 => {
(crates::Bindings::Stm32, "stm32f410", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F411 => {
(crates::Bindings::Stm32, "stm32f411", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F412 => {
(crates::Bindings::Stm32, "stm32f412", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F413 => {
(crates::Bindings::Stm32, "stm32f413", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F427 => {
(crates::Bindings::Stm32, "stm32f427", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F429 => {
(crates::Bindings::Stm32, "stm32f429", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F446 => {
(crates::Bindings::Stm32, "stm32f446", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32F469 => {
(crates::Bindings::Stm32, "stm32f469", &["adc", "dma", "exti", "gpio", "tim"])
}
Self::Stm32L4X1 => (crates::Bindings::Stm32, "stm32l4x1", &[
"dma", "exti", "gpio", "i2c", "rtc", "spi", "tim", "uart",
]),
Expand Down
19 changes: 3 additions & 16 deletions src/heap/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ pub fn display(w: &mut impl Write, layout: &[(u32, u32)]) -> Result<()> {
if *capacity == 0 {
continue;
}
writeln!(
w,
" {{ block = \"{}\", capacity = {} }},",
format_size(*block),
capacity
)?;
writeln!(w, " {{ block = \"{}\", capacity = {} }},", format_size(*block), capacity)?;
}
writeln!(w, "]")?;
Ok(())
Expand Down Expand Up @@ -108,12 +103,7 @@ fn generate(
shell.reset()?;
write!(shell, "# Fragmentation: ")?;
shell.set_color(ColorSpec::new().set_bold(true))?;
writeln!(
shell,
"{} / {:.2}%",
frag,
f64::from(frag) / f64::from(size) * 100.0
)?;
writeln!(shell, "{} / {:.2}%", frag, f64::from(frag) / f64::from(size) * 100.0)?;
shell.reset()?;
writeln!(shell)?;
display(&mut stdout(), &output)?;
Expand Down Expand Up @@ -155,10 +145,7 @@ fn shrink(input: &[(u32, u32)], output: &mut [(u32, u32)], frag: &mut u32, cutof
}

fn extend(output: &mut [(u32, u32)], size: u32) {
let mut used = output
.iter()
.map(|(block, capacity)| block * capacity)
.sum::<u32>();
let mut used = output.iter().map(|(block, capacity)| block * capacity).sum::<u32>();
let count = output.len() as u32;
let free = f64::from(size - used);
for ((block, capacity), ratio) in output.iter_mut().zip(ratios(count)) {
Expand Down
22 changes: 3 additions & 19 deletions src/heap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ pub struct TraceEntry {
impl HeapCmd {
/// Runs the `drone heap` command.
pub fn run(&self, shell: &mut StandardStream) -> Result<()> {
let Self {
trace_file,
size,
big_endian,
heap_sub_cmd,
} = self;
let Self { trace_file, size, big_endian, heap_sub_cmd } = self;
let size = size.map(Ok).unwrap_or_else(|| {
config::Config::read_from_current_dir().map(|config| config.heap.size)
})?;
Expand Down Expand Up @@ -65,23 +60,12 @@ fn print_stats(
shell.reset()?;
let mut used = 0;
for (size, entry) in trace {
writeln!(
shell,
" {: >6} {:11} {:13}",
format_size(*size),
entry.max,
entry.total
)?;
writeln!(shell, " {: >6} {:11} {:13}", format_size(*size), entry.max, entry.total)?;
used += size * entry.max;
}
write!(shell, "Maximum memory usage: ")?;
shell.set_color(ColorSpec::new().set_bold(true))?;
writeln!(
shell,
"{} / {:.2}%",
used,
f64::from(used) / f64::from(size) * 100.0
)?;
writeln!(shell, "{} / {:.2}%", used, f64::from(used) / f64::from(size) * 100.0)?;
shell.reset()?;
Ok(())
}
Expand Down
12 changes: 2 additions & 10 deletions src/heap/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,8 @@ fn parser<R: Read>(
let mut header = [0; 2];
let mut value = [0; 4];
let parse_u32 = move |bytes| {
let value = if big_endian {
u32::from_be_bytes(bytes)
} else {
u32::from_le_bytes(bytes)
};
if value == 0 {
Err(Error::InvalidValue)
} else {
Ok(value ^ KEY)
}
let value = if big_endian { u32::from_be_bytes(bytes) } else { u32::from_le_bytes(bytes) };
if value == 0 { Err(Error::InvalidValue) } else { Ok(value ^ KEY) }
};
static move || {
loop {
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ use termcolor::StandardStream;
impl Cli {
/// Runs the program.
pub fn run(self) -> Result<()> {
let Self {
cmd,
color,
verbosity,
} = self;
let Self { cmd, color, verbosity } = self;
let log_level = match verbosity {
0 => Level::Error,
1 => Level::Warn,
Expand Down
36 changes: 6 additions & 30 deletions src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ use termcolor::{Color, ColorSpec, StandardStream, WriteColor};
impl NewCmd {
/// Runs the `drone new` command.
pub fn run(&self, shell: &mut StandardStream) -> Result<()> {
let Self {
path,
device,
flash_size,
ram_size,
probe,
probe_itm,
name,
toolchain,
} = self;
let Self { path, device, flash_size, ram_size, probe, probe_itm, name, toolchain } = self;
let registry = Registry::new()?;
let name = name.as_ref().map(String::as_str).map_or_else(
|| {
Expand All @@ -49,10 +40,8 @@ impl NewCmd {
},
Ok,
)?;
let underscore_name = name
.chars()
.map(|c| if c == '-' { '_' } else { c })
.collect::<String>();
let underscore_name =
name.chars().map(|c| if c == '-' { '_' } else { c }).collect::<String>();

cargo_new(path, &toolchain)?;
src_main_rs(path, shell)?;
Expand All @@ -66,16 +55,7 @@ impl NewCmd {
}
}
cargo_toml(path, &name, &device, &registry, shell)?;
drone_toml(
path,
&device,
*flash_size,
*ram_size,
&probe,
&probe_itm,
&registry,
shell,
)?;
drone_toml(path, &device, *flash_size, *ram_size, &probe, &probe_itm, &registry, shell)?;
justfile(path, &device, &registry, shell)?;
rust_toolchain(path, &toolchain, &registry, shell)?;
cargo_config(path, &registry, shell)?;
Expand Down Expand Up @@ -191,13 +171,9 @@ fn drone_toml(
) -> Result<()> {
let path = path.join("Drone.toml");
let mut file = File::create(&path)?;
let probe = probe
.as_ref()
.unwrap_or_else(|| device.probes().first().unwrap());
let probe = probe.as_ref().unwrap_or_else(|| device.probes().first().unwrap());
file.write_all(
registry
.new_drone_toml(device, flash_size, ram_size, probe, probe_itm)?
.as_bytes(),
registry.new_drone_toml(device, flash_size, ram_size, probe, probe_itm)?.as_bytes(),
)?;
print_created(shell, "Drone.toml")
}
Expand Down
Loading

0 comments on commit f572e58

Please sign in to comment.