mnml/server/src/util.rs
2019-06-01 14:59:01 +10:00

40 lines
789 B
Rust

// use net::Db;
// Db Commons
// use failure::Error;
// pub fn startup(db: Db) -> Result<(), Error> {
// let tx = db.transaction()?;
// info!("running startup fns");
// match tx.commit() {
// Ok(_) => {
// info!("startup processes completed");
// Ok(())
// },
// Err(e) => Err(format_err!("failed to commit startup tx {:?}", e)),
// }
// }
pub trait IntPct {
fn pct(self, pct: u64) -> u64;
}
impl IntPct for u64 {
fn pct(self, pct: u64) -> u64 {
self * pct / 100
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn int_pct_test() {
assert_eq!(100.pct(110), 110);
assert_eq!(100.pct(50), 50);
assert_eq!(1.pct(200), 2);
assert_eq!(1.pct(50), 0);
}
}