rustfmt: libflate, libfmt_macros, libgetopts, libgraphviz, liblog, librand
This commit is contained in:
parent
0dfd875b6e
commit
5fb6531903
12 changed files with 502 additions and 477 deletions
|
@ -82,7 +82,7 @@ impl Drop for Bytes {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[link(name = "miniz", kind = "static")]
|
#[link(name = "miniz", kind = "static")]
|
||||||
extern {
|
extern "C" {
|
||||||
/// Raw miniz compression function.
|
/// Raw miniz compression function.
|
||||||
fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
|
fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
|
||||||
src_buf_len: size_t,
|
src_buf_len: size_t,
|
||||||
|
|
|
@ -187,7 +187,7 @@ impl<'a> Parser<'a> {
|
||||||
Parser {
|
Parser {
|
||||||
input: s,
|
input: s,
|
||||||
cur: s.char_indices().peekable(),
|
cur: s.char_indices().peekable(),
|
||||||
errors: vec!(),
|
errors: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ impl<'a> Parser<'a> {
|
||||||
if c.is_whitespace() {
|
if c.is_whitespace() {
|
||||||
self.cur.next();
|
self.cur.next();
|
||||||
} else {
|
} else {
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,9 +274,7 @@ impl<'a> Parser<'a> {
|
||||||
ArgumentIs(i)
|
ArgumentIs(i)
|
||||||
} else {
|
} else {
|
||||||
match self.cur.peek() {
|
match self.cur.peek() {
|
||||||
Some(&(_, c)) if c.is_alphabetic() => {
|
Some(&(_, c)) if c.is_alphabetic() => ArgumentNamed(self.word()),
|
||||||
ArgumentNamed(self.word())
|
|
||||||
}
|
|
||||||
_ => ArgumentNext,
|
_ => ArgumentNext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,7 +292,7 @@ impl<'a> Parser<'a> {
|
||||||
ty: &self.input[..0],
|
ty: &self.input[..0],
|
||||||
};
|
};
|
||||||
if !self.consume(':') {
|
if !self.consume(':') {
|
||||||
return spec
|
return spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill character
|
// fill character
|
||||||
|
@ -419,7 +417,7 @@ impl<'a> Parser<'a> {
|
||||||
found = true;
|
found = true;
|
||||||
self.cur.next();
|
self.cur.next();
|
||||||
} else {
|
} else {
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if found {
|
if found {
|
||||||
|
@ -447,7 +445,7 @@ mod tests {
|
||||||
precision: CountImplied,
|
precision: CountImplied,
|
||||||
width: CountImplied,
|
width: CountImplied,
|
||||||
ty: "",
|
ty: "",
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn musterr(s: &str) {
|
fn musterr(s: &str) {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -416,10 +416,10 @@ impl<'a> Id<'a> {
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
}
|
}
|
||||||
if !chars.all(is_constituent) {
|
if !chars.all(is_constituent) {
|
||||||
return Err(())
|
return Err(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(Id{ name: name });
|
return Ok(Id { name: name });
|
||||||
|
|
||||||
fn is_letter_or_underscore(c: char) -> bool {
|
fn is_letter_or_underscore(c: char) -> bool {
|
||||||
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
|
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
|
||||||
|
@ -496,8 +496,7 @@ pub trait Labeller<'a,N,E> {
|
||||||
/// Escape tags in such a way that it is suitable for inclusion in a
|
/// Escape tags in such a way that it is suitable for inclusion in a
|
||||||
/// Graphviz HTML label.
|
/// Graphviz HTML label.
|
||||||
pub fn escape_html(s: &str) -> String {
|
pub fn escape_html(s: &str) -> String {
|
||||||
s
|
s.replace("&", "&")
|
||||||
.replace("&", "&")
|
|
||||||
.replace("\"", """)
|
.replace("\"", """)
|
||||||
.replace("<", "<")
|
.replace("<", "<")
|
||||||
.replace(">", ">")
|
.replace(">", ">")
|
||||||
|
@ -523,9 +522,11 @@ impl<'a> LabelText<'a> {
|
||||||
// not escaping \\, since Graphviz escString needs to
|
// not escaping \\, since Graphviz escString needs to
|
||||||
// interpret backslashes; see EscStr above.
|
// interpret backslashes; see EscStr above.
|
||||||
'\\' => f(c),
|
'\\' => f(c),
|
||||||
_ => for c in c.escape_default() {
|
_ => {
|
||||||
|
for c in c.escape_default() {
|
||||||
f(c)
|
f(c)
|
||||||
},
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn escape_str(s: &str) -> String {
|
fn escape_str(s: &str) -> String {
|
||||||
|
@ -553,11 +554,13 @@ impl<'a> LabelText<'a> {
|
||||||
fn pre_escaped_content(self) -> Cow<'a, str> {
|
fn pre_escaped_content(self) -> Cow<'a, str> {
|
||||||
match self {
|
match self {
|
||||||
EscStr(s) => s,
|
EscStr(s) => s,
|
||||||
LabelStr(s) => if s.contains('\\') {
|
LabelStr(s) => {
|
||||||
|
if s.contains('\\') {
|
||||||
(&*s).escape_default().into_cow()
|
(&*s).escape_default().into_cow()
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
},
|
}
|
||||||
|
}
|
||||||
HtmlStr(s) => s,
|
HtmlStr(s) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +741,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edge(from: usize, to: usize, label: &'static str, style: Style) -> Edge {
|
fn edge(from: usize, to: usize, label: &'static str, style: Style) -> Edge {
|
||||||
Edge { from: from, to: to, label: label, style: style }
|
Edge {
|
||||||
|
from: from,
|
||||||
|
to: to,
|
||||||
|
label: label,
|
||||||
|
style: style,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LabelledGraph {
|
struct LabelledGraph {
|
||||||
|
@ -1009,7 +1017,7 @@ r#"digraph single_cyclic_node {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hasse_diagram() {
|
fn hasse_diagram() {
|
||||||
let labels = AllNodesLabelled(vec!("{x,y}", "{x}", "{y}", "{}"));
|
let labels = AllNodesLabelled(vec!["{x,y}", "{x}", "{y}", "{}"]);
|
||||||
let r = test_input(LabelledGraph::new("hasse_diagram",
|
let r = test_input(LabelledGraph::new("hasse_diagram",
|
||||||
labels,
|
labels,
|
||||||
vec![edge(0, 1, "", Style::None),
|
vec![edge(0, 1, "", Style::None),
|
||||||
|
@ -1033,7 +1041,7 @@ r#"digraph hasse_diagram {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn left_aligned_text() {
|
fn left_aligned_text() {
|
||||||
let labels = AllNodesLabelled(vec!(
|
let labels = AllNodesLabelled(vec![
|
||||||
"if test {\
|
"if test {\
|
||||||
\\l branch1\
|
\\l branch1\
|
||||||
\\l} else {\
|
\\l} else {\
|
||||||
|
@ -1043,7 +1051,7 @@ r#"digraph hasse_diagram {
|
||||||
\\l",
|
\\l",
|
||||||
"branch1",
|
"branch1",
|
||||||
"branch2",
|
"branch2",
|
||||||
"afterward"));
|
"afterward"]);
|
||||||
|
|
||||||
let mut writer = Vec::new();
|
let mut writer = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
|
||||||
if let Some(m) = mods {
|
if let Some(m) = mods {
|
||||||
for s in m.split(',') {
|
for s in m.split(',') {
|
||||||
if s.is_empty() {
|
if s.is_empty() {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
let mut parts = s.split('=');
|
let mut parts = s.split('=');
|
||||||
let (log_level, name) = match (parts.next(),
|
let (log_level, name) = match (parts.next(),
|
||||||
|
@ -69,13 +69,13 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
|
||||||
Some(num) => (num, Some(part0)),
|
Some(num) => (num, Some(part0)),
|
||||||
_ => {
|
_ => {
|
||||||
println!("warning: invalid logging spec '{}', ignoring it", part1);
|
println!("warning: invalid logging spec '{}', ignoring it", part1);
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("warning: invalid logging spec '{}', ignoring it", s);
|
println!("warning: invalid logging spec '{}', ignoring it", s);
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dirs.push(LogDirective {
|
dirs.push(LogDirective {
|
||||||
|
|
|
@ -296,7 +296,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) {
|
||||||
n => {
|
n => {
|
||||||
let filter = mem::transmute::<_, &String>(n);
|
let filter = mem::transmute::<_, &String>(n);
|
||||||
if !args.to_string().contains(filter) {
|
if !args.to_string().contains(filter) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ pub fn mod_enabled(level: u32, module: &str) -> bool {
|
||||||
// check being expanded manually in the logging macro, this function checks
|
// check being expanded manually in the logging macro, this function checks
|
||||||
// the log level again.
|
// the log level again.
|
||||||
if level > unsafe { LOG_LEVEL } {
|
if level > unsafe { LOG_LEVEL } {
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This assertion should never get tripped unless we're in an at_exit
|
// This assertion should never get tripped unless we're in an at_exit
|
||||||
|
@ -393,9 +393,7 @@ fn enabled(level: u32, module: &str, iter: slice::Iter<directive::LogDirective>)
|
||||||
for directive in iter.rev() {
|
for directive in iter.rev() {
|
||||||
match directive.name {
|
match directive.name {
|
||||||
Some(ref name) if !module.starts_with(&name[..]) => {}
|
Some(ref name) if !module.starts_with(&name[..]) => {}
|
||||||
Some(..) | None => {
|
Some(..) | None => return level <= directive.level,
|
||||||
return level <= directive.level
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
level <= DEFAULT_LOG_LEVEL
|
level <= DEFAULT_LOG_LEVEL
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
use {Rng, SeedableRng, Rand};
|
use {Rng, SeedableRng, Rand};
|
||||||
|
|
||||||
const KEY_WORDS : usize = 8; // 8 words for the 256-bit key
|
const KEY_WORDS: usize = 8; // 8 words for the 256-bit key
|
||||||
const STATE_WORDS : usize = 16;
|
const STATE_WORDS: usize = 16;
|
||||||
const CHACHA_ROUNDS: usize = 20; // Cryptographically secure from 8 upwards as of this writing
|
const CHACHA_ROUNDS: usize = 20; // Cryptographically secure from 8 upwards as of this writing
|
||||||
|
|
||||||
/// A random number generator that uses the ChaCha20 algorithm [1].
|
/// A random number generator that uses the ChaCha20 algorithm [1].
|
||||||
|
@ -77,7 +77,6 @@ fn core(output: &mut [u32; STATE_WORDS], input: &[u32; STATE_WORDS]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChaChaRng {
|
impl ChaChaRng {
|
||||||
|
|
||||||
/// Create an ChaCha random number generator using the default
|
/// Create an ChaCha random number generator using the default
|
||||||
/// fixed key of 8 zero words.
|
/// fixed key of 8 zero words.
|
||||||
pub fn new_unseeded() -> ChaChaRng {
|
pub fn new_unseeded() -> ChaChaRng {
|
||||||
|
@ -173,7 +172,6 @@ impl Rng for ChaChaRng {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
|
impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
|
||||||
|
|
||||||
fn reseed(&mut self, seed: &'a [u32]) {
|
fn reseed(&mut self, seed: &'a [u32]) {
|
||||||
// reset state
|
// reset state
|
||||||
self.init(&[0; KEY_WORDS]);
|
self.init(&[0; KEY_WORDS]);
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl Gamma {
|
||||||
|
|
||||||
let repr = match shape {
|
let repr = match shape {
|
||||||
1.0 => One(Exp::new(1.0 / scale)),
|
1.0 => One(Exp::new(1.0 / scale)),
|
||||||
0.0 ... 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
|
0.0...1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
|
||||||
_ => Large(GammaLargeShape::new_raw(shape, scale)),
|
_ => Large(GammaLargeShape::new_raw(shape, scale)),
|
||||||
};
|
};
|
||||||
Gamma { repr: repr }
|
Gamma { repr: repr }
|
||||||
|
@ -153,7 +153,8 @@ impl IndependentSample<f64> for GammaLargeShape {
|
||||||
loop {
|
loop {
|
||||||
let StandardNormal(x) = rng.gen::<StandardNormal>();
|
let StandardNormal(x) = rng.gen::<StandardNormal>();
|
||||||
let v_cbrt = 1.0 + self.c * x;
|
let v_cbrt = 1.0 + self.c * x;
|
||||||
if v_cbrt <= 0.0 { // a^3 <= 0 iff a <= 0
|
if v_cbrt <= 0.0 {
|
||||||
|
// a^3 <= 0 iff a <= 0
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,8 +118,10 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
|
||||||
for item in &mut *items {
|
for item in &mut *items {
|
||||||
running_total = match running_total.checked_add(item.weight) {
|
running_total = match running_total.checked_add(item.weight) {
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
None => panic!("WeightedChoice::new called with a total weight larger than a \
|
None => {
|
||||||
usize can contain"),
|
panic!("WeightedChoice::new called with a total weight larger than a usize \
|
||||||
|
can contain")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
item.weight = running_total;
|
item.weight = running_total;
|
||||||
|
@ -199,7 +201,6 @@ mod ziggurat_tables;
|
||||||
/// * `pdf`: the probability density function
|
/// * `pdf`: the probability density function
|
||||||
/// * `zero_case`: manual sampling from the tail when we chose the
|
/// * `zero_case`: manual sampling from the tail when we chose the
|
||||||
/// bottom box (i.e. i == 0)
|
/// bottom box (i.e. i == 0)
|
||||||
|
|
||||||
// the perf improvement (25-50%) is definitely worth the extra code
|
// the perf improvement (25-50%) is definitely worth the extra code
|
||||||
// size from force-inlining.
|
// size from force-inlining.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
@ -54,7 +54,6 @@ static EMPTY: IsaacRng = IsaacRng {
|
||||||
};
|
};
|
||||||
|
|
||||||
impl IsaacRng {
|
impl IsaacRng {
|
||||||
|
|
||||||
/// Create an ISAAC random number generator using the default
|
/// Create an ISAAC random number generator using the default
|
||||||
/// fixed seed.
|
/// fixed seed.
|
||||||
pub fn new_unseeded() -> IsaacRng {
|
pub fn new_unseeded() -> IsaacRng {
|
||||||
|
|
|
@ -306,8 +306,7 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
|
||||||
type Item = char;
|
type Item = char;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<char> {
|
fn next(&mut self) -> Option<char> {
|
||||||
const GEN_ASCII_STR_CHARSET: &'static [u8] =
|
const GEN_ASCII_STR_CHARSET: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
|
||||||
abcdefghijklmnopqrstuvwxyz\
|
abcdefghijklmnopqrstuvwxyz\
|
||||||
0123456789";
|
0123456789";
|
||||||
Some(*self.rng.choose(GEN_ASCII_STR_CHARSET).unwrap() as char)
|
Some(*self.rng.choose(GEN_ASCII_STR_CHARSET).unwrap() as char)
|
||||||
|
|
|
@ -202,7 +202,7 @@ tuple_impl!{A, B, C, D, E, F, G, H, I, J}
|
||||||
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K}
|
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K}
|
||||||
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L}
|
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L}
|
||||||
|
|
||||||
impl<T:Rand> Rand for Option<T> {
|
impl<T: Rand> Rand for Option<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Option<T> {
|
fn rand<R: Rng>(rng: &mut R) -> Option<T> {
|
||||||
if rng.gen() {
|
if rng.gen() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue