Skip to content

Commit

Permalink
Add rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanArkhipov1999 committed Feb 7, 2024
1 parent f6a7efa commit 0be549f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Fmt
run: cargo fmt --all -- --check
2 changes: 1 addition & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ pub fn send_timer_information(_timer_information: TimerInformation) {
pub fn get_timers_information() -> TimersInformation {
// TODO: Some code, receiving information from other timers. It may be hardware dependent.
vec![10, 2, 3]
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod connection;
pub mod timer;
pub mod connection;
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::timer::Timer;
use std::thread;
use std::time::Duration;

mod timer;
mod connection;
mod timer;

fn main() {
let timer = Timer::new(0, 5, 0.1);
Expand All @@ -18,4 +18,3 @@ fn main() {

println!("Final ticks time: {}", timer.get_tick_counter());
}

16 changes: 13 additions & 3 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ pub struct Timer {

impl Timer {
/// Creates new timer.
pub fn new(tick_counter: TickType, synchronization_period: TickType, synchronization_scale: f64) -> Timer {
Timer { tick_counter: Arc::new(Mutex::new(tick_counter)), running: Arc::new(Mutex::new(false)), synchronization_period, synchronization_scale }
pub fn new(
tick_counter: TickType,
synchronization_period: TickType,
synchronization_scale: f64,
) -> Timer {
Timer {
tick_counter: Arc::new(Mutex::new(tick_counter)),
running: Arc::new(Mutex::new(false)),
synchronization_period,
synchronization_scale,
}
}

/// Starts timer ticking.
Expand Down Expand Up @@ -66,7 +75,8 @@ impl Timer {
// Local vote protocol.
let old_count = **_count;
for info in timers_information {
**_count += (synchronization_scale * (old_count - info).abs() as f64).round() as TickType;
**_count +=
(synchronization_scale * (old_count - info).abs() as f64).round() as TickType;
}
}
}
4 changes: 2 additions & 2 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(test)]
mod integration_tests {
use ma_rtos::timer::Timer;
use std::thread;
use std::time::Duration;
use ma_rtos::timer::Timer;

#[test]
/// Tests work of several timers.
Expand All @@ -27,4 +27,4 @@ mod integration_tests {
assert!(count2 <= 12);
assert!(count3 <= 5);
}
}
}
2 changes: 1 addition & 1 deletion tests/unit_tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(test)]
mod unit_tests {
use ma_rtos::timer::Timer;
use std::thread;
use std::time::Duration;
use ma_rtos::timer::Timer;

#[test]
/// Tests new function of timer.
Expand Down

0 comments on commit 0be549f

Please sign in to comment.