Skip to content

Commit

Permalink
Fix warnings (#42)
Browse files Browse the repository at this point in the history
* Fix warnings

* Revert warning fix
  • Loading branch information
ivnsch authored Jun 3, 2020
1 parent 410136f commit 56ac81f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 41 deletions.
30 changes: 0 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use once_cell::sync::OnceCell;
use persy::{Config, Persy, ValueMode};
use std::path::Path;
use tcn::TemporaryContactNumber;
use errors::Error;
mod networking;
mod ios;
Expand Down Expand Up @@ -35,18 +34,6 @@ pub const DB_UNINIT: &str = "DB not initialized";
// TODO since we're using DI put this in a dependency, to be consistent
pub static DB: OnceCell<Persy> = OnceCell::new();

fn u128_of_tcn(tcn: &TemporaryContactNumber) -> u128 {
u128::from_le_bytes(tcn.0)
}

// maybe we don't care about this one?
// leaving it here in case I need it as the library evolves
// TODO: consider deleting
// fn cen_of_u128(u: u128) -> ContactEventNumber {
// ContactEventNumber(u.to_le_bytes())
// }


// TODO refactor these (byte_vec_to) convertions or better way?

// TODO move to utils file or similar. Consider returning Result instead of panicking.
Expand All @@ -71,23 +58,6 @@ pub fn byte_vec_to_8_byte_array(bytes: Vec<u8>) -> [u8; 8] {
array
}


fn all_stored_tcns() -> Res<Vec<u128>> {
let mut out: Vec<u128> = Vec::new();

let items = DB
.get()
.ok_or(DB_UNINIT)?
.scan("tcn")?;

for (_id,content) in items {
let byte_array: [u8; 16] = byte_vec_to_16_byte_array(content);
let tcn_bits: u128 = u128::from_le_bytes(byte_array);
out.push(tcn_bits);
}
Ok(out)
}

// TODO (deleting of TCNs not critical for now)
// pub fn delete_cens_between(start: i64, end: i64) -> Res<()> {
// let db = DB.get().ok_or(DB_UNINIT)?;
Expand Down
2 changes: 1 addition & 1 deletion src/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Preferences for PreferencesImpl {

fn last_completed_reports_interval(&self, key: PreferencesKey) -> Option<ReportsInterval> {
match key {
LastCompletedReportsInterval => self.config.read().last_completed_reports_interval
PreferencesKey::LastCompletedReportsInterval => self.config.read().last_completed_reports_interval
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/reporting/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl MemoMapper for MemoMapperImpl {


// Version for now not handled
let version_result = extract(&bits, &Self::VERSION_MAPPER, next)
let _ = extract(&bits, &Self::VERSION_MAPPER, next)
.value (|v| next += v);

// TODO handle report time?
let time_result = extract(&bits, &Self::TIME_MAPPER, next)
let _ = extract(&bits, &Self::TIME_MAPPER, next)
.value (|v| next += v);

let earliest_symptom_time = extract(&bits, &Self::TIME_USER_INPUT_MAPPER, next)
Expand Down
4 changes: 0 additions & 4 deletions src/reports_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ pub fn next(&self) -> ReportsInterval {
self.end() < time.value
}

pub fn contains(&self, time: &UnixTime) -> bool {
(self.start()..self.end()).contains(&time.value)
}

pub fn create_for_with_default_length(time: &UnixTime) -> ReportsInterval {
Self::create_for(time, 21600)
}
Expand Down
8 changes: 4 additions & 4 deletions src/reports_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl TcnDao for TcnDaoImpl {
.ok_or(DB_UNINIT).map_err(Error::from)?
.scan("tcn").map_err(Error::from)?;

for (_id,content) in items {
for (_id, content) in items {
let byte_array: [u8; 24] = byte_vec_to_24_byte_array(content);
out.push(ObservedTcn::from_bytes(byte_array));
}
Expand Down Expand Up @@ -293,8 +293,8 @@ impl<'a,
.unwrap_or(ReportsInterval::create_for_with_default_length(time))
}

fn matching_reports(&self, startInterval: ReportsInterval, until: &UnixTime) -> Result<Vec<MatchedReportsChunk>, ServicesError> {
let sequence = Self::generate_intervals_sequence(startInterval, until);
fn matching_reports(&self, start_interval: ReportsInterval, until: &UnixTime) -> Result<Vec<MatchedReportsChunk>, ServicesError> {
let sequence = Self::generate_intervals_sequence(start_interval, until);
let reports = sequence.map (|interval| self.retrieve_reports(interval));
let matched_results = reports
.map (|interval| self.match_retrieved_reports_result(interval));
Expand Down Expand Up @@ -379,7 +379,7 @@ impl<'a,
matched_reports
}

fn interval_ending_before(mut intervals: Vec<ReportsInterval>, time: &UnixTime) -> Option<ReportsInterval> {
fn interval_ending_before(intervals: Vec<ReportsInterval>, time: &UnixTime) -> Option<ReportsInterval> {
// TODO shorter version of this?
let reversed: Vec<ReportsInterval> = intervals.into_iter().rev().collect();
reversed.into_iter().find(|i| i.ends_before(&time))
Expand Down

0 comments on commit 56ac81f

Please sign in to comment.