rustacronymrust-result

What does "T" stand for in Result<T, E> in Rust?


The official documentation makes a lot of references to T:

enum Result<T, E> {
    Ok(T),
    Err(E),
}

I gather that these are placeholder acronyms. While E should stand for "error", I'm not sure what T stands for.


Solution

  • It's a naming convention for a generic type.

    Generic types in Rust are typically named with a single capital letter. The non_camel_case_types warning enforces that the name starts with a capital letter, but it's just a warning and nothing prevents you to name it otherwise.

    T is the most commonly seen letter, you'll often see this where the item really doesn't care what the type represents, but there are some other letters commonly used in particular cases as follow: