Update crate.

Clippy.
Fmt.
This commit is contained in:
2017-09-14 09:49:29 +02:00
parent 2e7d5b0214
commit c27239c01b
5 changed files with 60 additions and 57 deletions

44
Cargo.lock generated
View File

@@ -2,20 +2,20 @@
name = "piar"
version = "0.1.0"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pbr 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"pbr 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "1.0.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "getopts"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -29,38 +29,38 @@ dependencies = [
[[package]]
name = "lazy_static"
version = "0.2.2"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.20"
version = "0.2.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pbr"
version = "0.3.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.16"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "time"
version = "0.1.36"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -75,13 +75,13 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "65922871abd2f101a2eb0eaebadc66668e54a87ad9c3dd82520b5f86ede5eff9"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b"
"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
"checksum pbr 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f37516f7ab051df67430a6572735d7992fe74dde52554495eec459fb57da41f"
"checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753"
"checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade"
"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf"
"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915"
"checksum pbr 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e048e3afebb6c454bb1c5d0fe73fda54698b4715d78ed8e7302447c37736d23a"
"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509"
"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"

View File

@@ -5,8 +5,8 @@ authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
[dependencies]
getopts = "0.2"
byteorder = "1.0"
pbr = "0.3"
byteorder = "1.1"
pbr = "1.0"
lazy_static = "0.2"
[profile.release]

View File

@@ -1,7 +1,7 @@
pub fn get_byte(id: i32) -> u8 {
let pid: f64 = 4.0 * series(1, id) - 2.0 * series(4, id) - series(5, id) - series(6, id);
let y: f64 = (pid - (pid as i32) as f64 + 1.0).abs();
let y: f64 = (pid - f64::from(pid as i32) + 1.0).abs();
let y = 16.0 * (y - y.floor());
((y as u8) << 4) | (16.0 * (y - y.floor())) as u8
@@ -15,23 +15,23 @@ fn series(m: i32, id: i32) -> f64 {
let mut s: f64 = 0.0;
for k in 0..id {
ak = (8 * k + m) as f64;
t = expm((id - k) as f64, ak);
ak = f64::from(8 * k + m);
t = expm(f64::from(id - k), ak);
s += t / ak;
s -= s.trunc();
s += t / ak;
s -= s.trunc();
}
for k in id..id + 101 {
ak = (8 * k + m) as f64;
t = 16f64.powi(id - k) / ak;
ak = f64::from(8 * k + m);
t = 16f64.powi(id - k) / ak;
if t < EPS {
break;
}
if t < EPS {
break;
}
s += t;
s -= s.trunc();
s += t;
s -= s.trunc();
}
s
@@ -67,19 +67,19 @@ fn expm(p: f64, ak: f64) -> f64 {
let mut r: f64 = 1.0;
for _ in 1..i + 1 {
if p >= pt {
r *= 16.0;
r -= (r / ak).trunc() * ak;
if p >= pt {
r *= 16.0;
r -= (r / ak).trunc() * ak;
p -= pt;
}
p -= pt;
}
pt *= 0.5;
pt *= 0.5;
if pt >= 1.0 {
r *= r;
r -= (r / ak).trunc() * ak;
}
if pt >= 1.0 {
r *= r;
r -= (r / ak).trunc() * ak;
}
}
r

1
src/lib.rs Normal file
View File

@@ -0,0 +1 @@

View File

@@ -1,6 +1,8 @@
#[macro_use] extern crate lazy_static;
extern crate getopts;
extern crate byteorder;
extern crate getopts;
#[macro_use]
extern crate lazy_static;
extern crate pbr;
@@ -13,7 +15,7 @@ use std::io::Cursor;
use std::collections::BTreeMap;
use getopts::Options;
use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use pbr::{ProgressBar, Units};
@@ -22,20 +24,20 @@ mod bbp;
struct Pi {
next: i32,
map: BTreeMap<u8, i32>
map: BTreeMap<u8, i32>,
}
impl Pi {
fn new() -> Self {
Pi {
next: 0,
map: BTreeMap::new()
map: BTreeMap::new(),
}
}
fn find(&mut self, byte: u8) -> i32 {
if self.map.contains_key(&byte) {
*self.map.get(&byte).unwrap()
self.map[&byte]
} else {
for i in self.next..i32::MAX {
if byte == bbp::get_byte(i) {
@@ -51,7 +53,7 @@ impl Pi {
}
fn print_usage(program: &str, opts: Options) {
fn print_usage(program: &str, opts: &Options) {
let brief = format!("Usage: {} [option] INPUT OUTPUT", program);
print!("{}", opts.usage(&brief));
}
@@ -69,13 +71,13 @@ fn main() {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(_) => {
print_usage(&program, opts);
std::process::exit(1);
print_usage(&program, &opts);
std::process::exit(1)
}
};
if matches.opt_present("help") {
print_usage(&program, opts);
print_usage(&program, &opts);
std::process::exit(0);
}
@@ -123,7 +125,7 @@ fn compress(input: &str, output: &str) {
let i = pi.find(b);
let mut index : Vec<u8> = vec![];
let mut index: Vec<u8> = vec![];
index.write_i32::<LittleEndian>(i).unwrap();