Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

Commit 29f7438

Browse files
committed
A few cleanups for fmt_macros, graphviz, apfloat, target, serialize and term
1 parent 971f0d6 commit 29f7438

File tree

3 files changed

+51
-53
lines changed

3 files changed

+51
-53
lines changed

terminfo/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ impl error::Error for Error {
6060

6161
fn cause(&self) -> Option<&dyn error::Error> {
6262
use self::Error::*;
63-
match self {
64-
&IoError(ref e) => Some(e),
63+
match *self {
64+
IoError(ref e) => Some(e),
6565
_ => None,
6666
}
6767
}
@@ -70,10 +70,10 @@ impl error::Error for Error {
7070
impl fmt::Display for Error {
7171
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7272
use self::Error::*;
73-
match self {
74-
&TermUnset => Ok(()),
75-
&MalformedTerminfo(ref e) => e.fmt(f),
76-
&IoError(ref e) => e.fmt(f),
73+
match *self {
74+
TermUnset => Ok(()),
75+
MalformedTerminfo(ref e) => e.fmt(f),
76+
IoError(ref e) => e.fmt(f),
7777
}
7878
}
7979
}
@@ -109,9 +109,9 @@ impl TermInfo {
109109
}
110110
// Keep the metadata small
111111
fn _from_path(path: &Path) -> Result<TermInfo, Error> {
112-
let file = File::open(path).map_err(|e| Error::IoError(e))?;
112+
let file = File::open(path).map_err(Error::IoError)?;
113113
let mut reader = BufReader::new(file);
114-
parse(&mut reader, false).map_err(|e| Error::MalformedTerminfo(e))
114+
parse(&mut reader, false).map_err(Error::MalformedTerminfo)
115115
}
116116
}
117117

terminfo/parm.rs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
1313
use self::Param::*;
1414
use self::States::*;
15-
use self::FormatState::*;
16-
use self::FormatOp::*;
1715

1816
use std::iter::repeat;
1917

@@ -36,9 +34,9 @@ enum States {
3634

3735
#[derive(Copy, PartialEq, Clone)]
3836
enum FormatState {
39-
FormatStateFlags,
40-
FormatStateWidth,
41-
FormatStatePrecision,
37+
Flags,
38+
Width,
39+
Precision,
4240
}
4341

4442
/// Types of parameters a capability can use
@@ -210,22 +208,22 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
210208
if let Some(arg) = stack.pop() {
211209
let flags = Flags::new();
212210
let res = format(arg, FormatOp::from_char(cur), flags)?;
213-
output.extend(res.iter().map(|x| *x));
211+
output.extend(res.iter().cloned());
214212
} else {
215213
return Err("stack is empty".to_string());
216214
}
217215
}
218216
':' | '#' | ' ' | '.' | '0'..='9' => {
219217
let mut flags = Flags::new();
220-
let mut fstate = FormatStateFlags;
218+
let mut fstate = FormatState::Flags;
221219
match cur {
222220
':' => (),
223221
'#' => flags.alternate = true,
224222
' ' => flags.space = true,
225-
'.' => fstate = FormatStatePrecision,
223+
'.' => fstate = FormatState::Precision,
226224
'0'..='9' => {
227225
flags.width = cur as usize - '0' as usize;
228-
fstate = FormatStateWidth;
226+
fstate = FormatState::Width;
229227
}
230228
_ => unreachable!(),
231229
}
@@ -318,43 +316,43 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
318316
(_, 'd') | (_, 'o') | (_, 'x') | (_, 'X') | (_, 's') => {
319317
if let Some(arg) = stack.pop() {
320318
let res = format(arg, FormatOp::from_char(cur), *flags)?;
321-
output.extend(res.iter().map(|x| *x));
319+
output.extend(res.iter().cloned());
322320
// will cause state to go to Nothing
323321
old_state = FormatPattern(*flags, *fstate);
324322
} else {
325323
return Err("stack is empty".to_string());
326324
}
327325
}
328-
(FormatStateFlags, '#') => {
326+
(FormatState::Flags, '#') => {
329327
flags.alternate = true;
330328
}
331-
(FormatStateFlags, '-') => {
329+
(FormatState::Flags, '-') => {
332330
flags.left = true;
333331
}
334-
(FormatStateFlags, '+') => {
332+
(FormatState::Flags, '+') => {
335333
flags.sign = true;
336334
}
337-
(FormatStateFlags, ' ') => {
335+
(FormatState::Flags, ' ') => {
338336
flags.space = true;
339337
}
340-
(FormatStateFlags, '0'..='9') => {
338+
(FormatState::Flags, '0'..='9') => {
341339
flags.width = cur as usize - '0' as usize;
342-
*fstate = FormatStateWidth;
340+
*fstate = FormatState::Width;
343341
}
344-
(FormatStateFlags, '.') => {
345-
*fstate = FormatStatePrecision;
342+
(FormatState::Flags, '.') => {
343+
*fstate = FormatState::Precision;
346344
}
347-
(FormatStateWidth, '0'..='9') => {
345+
(FormatState::Width, '0'..='9') => {
348346
let old = flags.width;
349347
flags.width = flags.width * 10 + (cur as usize - '0' as usize);
350348
if flags.width < old {
351349
return Err("format width overflow".to_string());
352350
}
353351
}
354-
(FormatStateWidth, '.') => {
355-
*fstate = FormatStatePrecision;
352+
(FormatState::Width, '.') => {
353+
*fstate = FormatState::Precision;
356354
}
357-
(FormatStatePrecision, '0'..='9') => {
355+
(FormatState::Precision, '0'..='9') => {
358356
let old = flags.precision;
359357
flags.precision = flags.precision * 10 + (cur as usize - '0' as usize);
360358
if flags.precision < old {
@@ -437,31 +435,31 @@ impl Flags {
437435

438436
#[derive(Copy, Clone)]
439437
enum FormatOp {
440-
FormatDigit,
441-
FormatOctal,
442-
FormatHex,
443-
FormatHEX,
444-
FormatString,
438+
Digit,
439+
Octal,
440+
LowerHex,
441+
UpperHex,
442+
String,
445443
}
446444

447445
impl FormatOp {
448446
fn from_char(c: char) -> FormatOp {
449447
match c {
450-
'd' => FormatDigit,
451-
'o' => FormatOctal,
452-
'x' => FormatHex,
453-
'X' => FormatHEX,
454-
's' => FormatString,
448+
'd' => FormatOp::Digit,
449+
'o' => FormatOp::Octal,
450+
'x' => FormatOp::LowerHex,
451+
'X' => FormatOp::UpperHex,
452+
's' => FormatOp::String,
455453
_ => panic!("bad FormatOp char"),
456454
}
457455
}
458456
fn to_char(self) -> char {
459457
match self {
460-
FormatDigit => 'd',
461-
FormatOctal => 'o',
462-
FormatHex => 'x',
463-
FormatHEX => 'X',
464-
FormatString => 's',
458+
FormatOp::Digit => 'd',
459+
FormatOp::Octal => 'o',
460+
FormatOp::LowerHex => 'x',
461+
FormatOp::UpperHex => 'X',
462+
FormatOp::String => 's',
465463
}
466464
}
467465
}
@@ -470,7 +468,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8>, String> {
470468
let mut s = match val {
471469
Number(d) => {
472470
match op {
473-
FormatDigit => {
471+
FormatOp::Digit => {
474472
if flags.sign {
475473
format!("{:+01$}", d, flags.precision)
476474
} else if d < 0 {
@@ -482,35 +480,35 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8>, String> {
482480
format!("{:01$}", d, flags.precision)
483481
}
484482
}
485-
FormatOctal => {
483+
FormatOp::Octal => {
486484
if flags.alternate {
487485
// Leading octal zero counts against precision.
488486
format!("0{:01$o}", d, flags.precision.saturating_sub(1))
489487
} else {
490488
format!("{:01$o}", d, flags.precision)
491489
}
492490
}
493-
FormatHex => {
491+
FormatOp::LowerHex => {
494492
if flags.alternate && d != 0 {
495493
format!("0x{:01$x}", d, flags.precision)
496494
} else {
497495
format!("{:01$x}", d, flags.precision)
498496
}
499497
}
500-
FormatHEX => {
498+
FormatOp::UpperHex => {
501499
if flags.alternate && d != 0 {
502500
format!("0X{:01$X}", d, flags.precision)
503501
} else {
504502
format!("{:01$X}", d, flags.precision)
505503
}
506504
}
507-
FormatString => return Err("non-number on stack with %s".to_string()),
505+
FormatOp::String => return Err("non-number on stack with %s".to_string()),
508506
}
509507
.into_bytes()
510508
}
511509
Words(s) => {
512510
match op {
513-
FormatString => {
511+
FormatOp::String => {
514512
let mut s = s.into_bytes();
515513
if flags.precision > 0 && flags.precision < s.len() {
516514
s.truncate(flags.precision);

win.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ impl<T: Write + Send + 'static> Terminal for WinConsole<T> {
198198
Ok(true)
199199
}
200200

201-
fn get_ref<'a>(&'a self) -> &'a T {
201+
fn get_ref(&self) -> &T {
202202
&self.buf
203203
}
204204

205-
fn get_mut<'a>(&'a mut self) -> &'a mut T {
205+
fn get_mut(&mut self) -> &mut T {
206206
&mut self.buf
207207
}
208208

0 commit comments

Comments
 (0)