     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73

    use std::fmt;

    #[cfg(all(feature = "color", not(target_os = "windows")))]
    use ansi_term::Colour::{Green, Red, Yellow};
    #[cfg(all(feature = "color", not(target_os = "windows")))]
    use ansi_term::ANSIString;

    /// Defines styles for different types of error messages. Defaults to Error=Red, Warning=Yellow,
    /// and Good=Green
    #[derive(Debug)]
    pub enum Format<T> {
        /// Defines the style used for errors, defaults to Red
        Error(T),
        /// Defines the style used for warnings, defaults to Yellow
        Warning(T),
        /// Defines the style used for good values, defaults to Green
        Good(T),
    }

    #[cfg(all(feature = "color", not(target_os = "windows")))]
    impl<T: AsRef<str>> Format<T> {
        fn format(&self) -> ANSIString {
            match *self {
                Format::Error(ref e) => Red.bold().paint(e.as_ref()),
                Format::Warning(ref e) => Yellow.paint(e.as_ref()),
                Format::Good(ref e) => Green.paint(e.as_ref()),
            }
        }

    }

    #[cfg(all(feature = "color", not(target_os = "windows")))]
    impl<T: AsRef<str>> fmt::Display for Format<T> {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{}", &self.format())
        }
    }

    #[cfg(any(not(feature = "color"), target_os = "windows"))]
    impl<T: fmt::Display> Format<T> {
        fn format(&self) -> &T {
            match *self {
                Format::Error(ref e) => e,
                Format::Warning(ref e) => e,
                Format::Good(ref e) => e,
            }
        }
    }

    #[cfg(any(not(feature = "color"), target_os = "windows"))]
    impl<T: fmt::Display> fmt::Display for Format<T> {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{}", &self.format())
        }
    }

    #[cfg(all(test, feature = "color", not(target_os = "windows")))]
    mod test {
        use super::Format;
        use ansi_term::Colour::{Green, Red, Yellow};

        #[test]
        fn colored_output() {
            let err = Format::Error("error");
            assert_eq!(&*format!("{}", err),
                       &*format!("{}", Red.bold().paint("error")));
            let good = Format::Good("good");
            assert_eq!(&*format!("{}", good), &*format!("{}", Green.paint("good")));
            let warn = Format::Warning("warn");
            assert_eq!(&*format!("{}", warn), &*format!("{}", Yellow.paint("warn")));
        }
    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)