Elements of Rust – Core Types and Traits A visual guide to the Rust type system focusing on langitems — built-in types and traits that support Rust syntax. This overview excludes standard library types like Vec, String, or HashMap because they are library structs. --- Scalar Types Primitive single-value types: Unsigned integers: u8 (8-bit, 0–255), u16 (16-bit), u32 (32-bit), u64 (64-bit), u128 (128-bit), usize (pointer-sized uint) Signed integers: i8 (-128–127), i16, i32, i64, i128, isize (pointer-sized int) Floating point: f32 (32-bit), f64 (64-bit) Reserved: f16 (16-bit float), f128 (128-bit float) Boolean: bool (true, false) Character: char (Unicode scalar values) --- Compound Types Multiple values grouped together: Tuple (T, U, ...) e.g. (0, true) Struct struct Foo { ... } e.g. Point { x: 1, y: 2 } Enum enum Foo { ... } e.g. Some(val) Union union Foo { ... } Array [T; N] e.g. [2, 3, 5] Unit type () (empty tuple) --- Unsized Types Types without a compile-time known size: Slice [T]: unsized array slice str: unsized string slice Trait objects dyn Trait: unsized trait object --- Borrowed Reference Types Reference forms with borrowing semantics: Shared reference &T (e.g. &x) Mutable reference &mut T (e.g. &mut x) --- Slice Types (References to Unsized Types) Shared array slice &[T] (e.g. &arr[i..j]) Mutable array slice &mut [T] (e.g. &mut arr[i..j]) Shared string slice &str (e.g. "text") Mutable string slice &mut str Shared trait object &dyn Trait (e.g. &err as &dyn Error) Mutable trait object &mut dyn Trait --- Range Types Represent ranges with various bounds: Range<T>: half-open range i..j RangeTo<T>: bounded above open ..j RangeFrom<T>: bounded below i.. RangeInclusive<T>: closed range i..=j RangeToInclusive<T>: bounded above closed ..=j RangeFull: unbounded .. --- Utility Types Option<T>: optional value (Some(val) or None) Result<T, E>: outcome with success or error (Ok(val), Err(e)) Ordering: comparison result (Less, Equal, Greater) Arguments: precompiled format string argument (e.g. "x is {}") --- Async Support Types Poll<T>: future completion (Pending, Ready(x)) Context<'a>: task context for async operations Pin<T>: immovable object pointer --- Anonymous Types Function item fn foo() Closure |x| x > threshold Async function async fn foo() Async closure async || f.await Existential type impl Trait (e.g., fn f() -> impl Trait) --- Unsafe Support Types UnsafeCell<T>: interior mutability ManuallyDrop<T>: inhibit destructor calls PhantomData<T>: type marker to act as if owning a T --- Raw Pointer Types const T: const raw pointer mut T: mutable raw pointer --- Function Pointer Type fn(T...) -> U: pointer to function (e.g., foo as fn()) --- Panic Support Types PanicInfo: info about a panic event Location: location in code where panic occurred --- Uninhabited Type ! (never): used in functions that never return (e.g., fn exit(i32) -> !) --- Traits Categories Access Operator Traits Deref: immutable dereference (p) DerefMut: mutable dereference (p = x) Index: immutable indexing (arr[i]) IndexMut: mutable indexing (arr[i] = x) RangeBounds<T>: range used as index (arr[i..j]) Comparison Operator Traits PartialOrd<T>: partial ordering (x < y) PartialEq<T>: partial equivalence (x == y) Ord<T>: total ordering Eq<T>: equivalence Arithmetic Operator Traits Add<T>: addition (x + y) Sub<T>: subtraction (x - y) Mul<T>: multiplication (x y) Div<T>: division (x / y) Rem<T>: remainder (x % y) Neg: negation (-x) Assignment variants: AddAssign<T> (`x