std::ascii::escape_default - Rust
Description: API documentation for the Rust `escape_default` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, escape_default

# 1.0.0[−][src]Function std::ascii::escape_default

ⓘImportant traits for EscapeDefault

### Important traits for EscapeDefault

`impl Iterator for EscapeDefault type Item = u8;`

    pub fn escape_default(c: u8) -> EscapeDefault

Returns an iterator that produces an escaped version of a `u8`.

The default is chosen with a bias toward producing literals that are legal in a variety of languages, including C++11 and similar C-family languages. The exact rules are:

- Tab is escaped as `\t`.
- Carriage return is escaped as `\r`.
- Line feed is escaped as `\n`.
- Single quote is escaped as `'`.
- Double quote is escaped as `"`.
- Backslash is escaped as `\`.
- Any character in the 'printable ASCII' range `0x20` .. `0x7e` inclusive is not escaped.
- Any other chars are given hex escapes of the form '\xNN'.
- Unicode escapes are never generated by this function.

# Examples

    use std::ascii;

    let escaped = ascii::escape_default(b'0').next().unwrap();
    assert_eq!(b'0', escaped);

    let mut escaped = ascii::escape_default(b'\t');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b't', escaped.next().unwrap());

    let mut escaped = ascii::escape_default(b'\r');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b'r', escaped.next().unwrap());

    let mut escaped = ascii::escape_default(b'\n');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b'n', escaped.next().unwrap());

    let mut escaped = ascii::escape_default(b'\'');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b'\'', escaped.next().unwrap());

    let mut escaped = ascii::escape_default(b'"');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b'"', escaped.next().unwrap());

    let mut escaped = ascii::escape_default(b'\\');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b'\\', escaped.next().unwrap());

    let mut escaped = ascii::escape_default(b'\x9d');

    assert_eq!(b'\\', escaped.next().unwrap());
    assert_eq!(b'x', escaped.next().unwrap());
    assert_eq!(b'9', escaped.next().unwrap());
    assert_eq!(b'd', escaped.next().unwrap());Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## 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`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)