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.
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.
Copyright © 2021 Jogjafile Inc.
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:If the type is an error type:
E
. Example:If the type is a predicate:
P
. Example:If the type is a function type:
F
,G
, etc. Example:If the type is the return type of a generic function:
R
. Example:If the type is a key type in some map:
K
. Example:If the type is a value type in some map:
V
. Example:If the type is an implementation of
Iterator
:I
. Example:If the type is an implementation of
Read
:R
. Example:If the type is an implementation of
Write
:W
. Example:If the type is an implementation of
ToSocketAddrs
:A
. Example:If the type is a path (ie. implements
AsRef
<
Path
>
):P
. Example:Everything else:
T
,U
, etc., usually in alphabetical order.