as - Rust
Description: API documentation for the Rust `as` keyword in crate `std`.
Keywords: rust, rustlang, rust-lang, as

# [−]Keyword as

Cast between types, or rename an import.

`as` is most commonly used to turn primitive types into other primitive types, but it has other uses that include turning pointers into addresses, addresses into pointers, and pointers into other pointers.

    let thing1: u8 = 89.0 as u8;
    assert_eq!('B' as u32, 66);
    assert_eq!(thing1 as char, 'Y');
    let thing2: f32 = thing1 as f32 + 10.5;
    assert_eq!(true as u8 + thing2 as u8, 100);Run

In general, any cast that can be performed via ascribing the type can also be done using `as`, so instead of writing `let x: u32 = 123`, you can write `let x = 123 as u32` (Note: `let x: u32 = 123` would be best in that situation). The same is not true in the other direction, however, explicitly using `as` allows a few more coercions that aren't allowed implicitly, such as changing the type of a raw pointer or turning closures into raw pointers.

Other places `as` is used include as extra syntax for `crate` and `use`, to change the name something is imported as.

For more information on what `as` is capable of, see the Reference

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