Skip to content

Commit

Permalink
Update Show/String to Debug/Display
Browse files Browse the repository at this point in the history
This commit replaces usage of the Show and fmt::String traits with
the Debug and Display traits. This was required to fix breaking
changes introduced by rust-lang/rust#21457. Additionally, the
superfluous `detail` method on `docopt::Error` was removed as it no
longer exists in the trait. Also, hi!
  • Loading branch information
ianbollinger committed Jan 23, 2015
1 parent 9801d52 commit 57a7955
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
17 changes: 8 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@
//! // This is easy. The decoder will automatically restrict values to
//! // strings that match one of the enum variants.
//! #[derive(RustcDecodable)]
//! # #[derive(PartialEq, Show)]
//! # #[derive(Debug, PartialEq)]
//! enum Emit { Asm, Ir, Bc, Obj, Link }
//!
//! // This one is harder because we want the user to specify an integer,
//! // but restrict it to a specific range. So we implement `Decodable`
//! // ourselves.
//! # #[derive(PartialEq, Show)]
//! # #[derive(Debug, PartialEq)]
//! enum OptLevel { Zero, One, Two, Three }
//!
//! impl rustc_serialize::Decodable for OptLevel {
Expand Down Expand Up @@ -281,7 +281,7 @@ macro_rules! regex(
/// .and_then(|d| d.parse())
/// .unwrap_or_else(|e| e.exit());
/// ```
#[derive(Show)]
#[derive(Debug)]
pub enum Error {
/// Parsing the usage string failed.
///
Expand Down Expand Up @@ -356,7 +356,7 @@ impl Error {
}
}

impl fmt::String for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
WithProgramUsage(ref other, ref usage) => {
Expand Down Expand Up @@ -389,7 +389,6 @@ impl StdError for Error {
}
}

fn detail(&self) -> Option<String> { Some(self.to_string()) }
fn cause(&self) -> Option<&StdError> {
match *self {
WithProgramUsage(ref cause, _) => Some(&**cause as &StdError),
Expand Down Expand Up @@ -418,7 +417,7 @@ impl<'a> StrAllocating for &'a str {
/// The main Docopt type, which is constructed with a Docopt usage string.
///
/// This can be used to match command line arguments to produce a `ArgvMap`.
#[derive(Clone, Show)]
#[derive(Clone, Debug)]
pub struct Docopt {
p: Parser,
argv: Option<Vec<String>>,
Expand Down Expand Up @@ -741,7 +740,7 @@ impl ArgvMap {
}
}

impl fmt::Show for ArgvMap {
impl fmt::Debug for ArgvMap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.len() == 0 {
return write!(f, "{{EMPTY}}");
Expand Down Expand Up @@ -776,7 +775,7 @@ impl fmt::Show for ArgvMap {
///
/// The various `as_{bool,count,str,vec}` methods provide convenient access
/// to values without destructuring manually.
#[derive(Clone, PartialEq, Show)]
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
/// A boolean value from a flag that has no argument.
///
Expand Down Expand Up @@ -879,7 +878,7 @@ pub struct Decoder {
stack: Vec<DecoderItem>,
}

#[derive(Show)]
#[derive(Debug)]
struct DecoderItem {
key: String,
struct_field: String,
Expand Down
18 changes: 9 additions & 9 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Parser {
}
}

impl fmt::Show for Parser {
impl fmt::Debug for Parser {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn sorted<T: Ord>(mut xs: Vec<T>) -> Vec<T> {
xs.sort(); xs
Expand Down Expand Up @@ -585,7 +585,7 @@ impl<'a> PatParser<'a> {
}
}

#[derive(Clone, Show)]
#[derive(Clone, Debug)]
enum Pattern {
Alternates(Vec<Pattern>),
Sequence(Vec<Pattern>),
Expand All @@ -594,15 +594,15 @@ enum Pattern {
PatAtom(Atom),
}

#[derive(PartialEq, Eq, Ord, Hash, Clone, Show)]
#[derive(PartialEq, Eq, Ord, Hash, Clone, Debug)]
pub enum Atom {
Short(char),
Long(String),
Command(String),
Positional(String),
}

#[derive(Clone, Show)]
#[derive(Clone, Debug)]
pub struct Options {
/// Set to true if this atom is ever repeated in any context.
/// For positional arguments, non-argument flags and commands, repetition
Expand All @@ -620,7 +620,7 @@ pub struct Options {
pub is_desc: bool,
}

#[derive(Clone, Show, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Argument {
Zero,
One(Option<String>), // optional default value
Expand Down Expand Up @@ -758,7 +758,7 @@ impl PartialOrd for Atom {
}
}

impl fmt::String for Atom {
impl fmt::Display for Atom {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Short(c) => write!(f, "-{}", c),
Expand Down Expand Up @@ -809,7 +809,7 @@ pub struct Argv<'a> {
options_first: bool,
}

#[derive(Clone, Show)]
#[derive(Clone, Debug)]
struct ArgvToken {
atom: Atom,
arg: Option<String>,
Expand Down Expand Up @@ -929,7 +929,7 @@ impl<'a> Argv<'a> {
}
}

impl<'a> fmt::Show for Argv<'a> {
impl<'a> fmt::Debug for Argv<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(writeln!(f, "Positional: {:?}", self.positional));
try!(writeln!(f, "Flags: {:?}", self.flags));
Expand All @@ -942,7 +942,7 @@ struct Matcher<'a, 'b:'a> {
argv: &'a Argv<'b>,
}

#[derive(Clone, PartialEq, Show)]
#[derive(Clone, Debug, PartialEq)]
struct MState {
argvi: usize, // index into Argv.positional
counts: HashMap<Atom, usize>, // flags remaining for pattern consumption
Expand Down
4 changes: 2 additions & 2 deletions src/synonym.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::collections::hash_map::{Hasher, Iter, Keys};
use std::fmt::Show;
use std::fmt::Debug;
use std::hash::Hash;
use std::iter::FromIterator;
use std::mem;
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<K: Eq + Hash<Hasher> + Clone, V> FromIterator<(K, V)> for SynonymMap<K, V>
}
}

impl<K: Eq + Hash<Hasher> + Show, V: Show> Show for SynonymMap<K, V> {
impl<K: Eq + Hash<Hasher> + Debug, V: Debug> Debug for SynonymMap<K, V> {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
try!(self.vals.fmt(f));
write!(f, " (synomyns: {:?})", self.syns)
Expand Down
2 changes: 1 addition & 1 deletion src/wordlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Which will only include 'a', 'b' and 'c' in the wordlist if
'your-command --help' contains a positional argument named 'arg'.
";

#[derive(RustcDecodable, Show)]
#[derive(Debug, RustcDecodable)]
struct Args {
arg_name: Vec<String>,
arg_possibles: Vec<String>,
Expand Down

0 comments on commit 57a7955

Please sign in to comment.