]> git.proxmox.com Git - rustc.git/blob - src/doc/reference/src/glossary.md
New upstream version 1.25.0+dfsg1
[rustc.git] / src / doc / reference / src / glossary.md
1 # Glossary
2
3 ### Abstract Syntax Tree
4
5 An ‘abstract syntax tree’, or ‘AST’, is an intermediate representation of
6 the structure of the program when the compiler is compiling it.
7
8 ### Alignment
9
10 The alignment of a value specifies what addresses values are preferred to
11 start at. Always a power of two. References to a value must be aligned.
12 [More][alignment].
13
14 ### Arity
15
16 Arity refers to the number of arguments a function or operator takes.
17 For some examples, `f(2, 3)` and `g(4, 6)` have arity 2, while `h(8, 2, 6)`
18 has arity 3. The `!` operator has arity 1.
19
20 ### Array
21
22 An array, sometimes also called a fixed-size array or an inline array, is a value
23 describing a collection of elements, each selected by an index that can be computed
24 at run time by the program. It occupies a contiguous region of memory.
25
26 ### Associated Item
27
28 An associated item is an item that is associated with another item. Associated
29 items are defined in [implementations] and declared in [traits]. Only functions,
30 constants, and type aliases can be associated.
31
32 ### Bound
33
34 Bounds are constraints on a type or trait. For example, if a bound
35 is placed on the argument a function takes, types passed to that function
36 must abide by that constraint.
37
38 ### Combinator
39
40 Combinators are higher-order functions that apply only functions and
41 earlier defined combinators to provide a result from its arguments.
42 They can be used to manage control flow in a modular fashion.
43
44 ### Dispatch
45
46 Dispatch is the mechanism to determine which specific version of code is actually
47 run when it involves polymorphism. Two major forms of dispatch are static dispatch and
48 dynamic dispatch. While Rust favors static dispatch, it also supports dynamic dispatch
49 through a mechanism called ‘trait objects’.
50
51 ### Dynamically Sized Type
52
53 A dynamically sized type (DST) is a type without a statically known size or alignment.
54
55 ### Expression
56
57 An expression is a combination of values, constants, variables, operators
58 and functions that evaluate to a single value, with or without side-effects.
59
60 For example, `2 + (3 * 4)` is an expression that returns the value 14.
61
62 ### Initialized
63
64 A variable is initialized if it has been assigned a value and hasn't since been
65 moved from. All other memory locations are assumed to be initialized. Only
66 unsafe Rust can create such a memory without initializing it.
67
68 ### Nominal Types
69
70 Types that can be referred to by a path directly. Specifically [enums],
71 [structs], [unions], and [trait objects].
72
73 ### Object Safe Traits
74
75 [Traits] that can be used as [trait objects]. Only traits that follow specific
76 [rules][object safety] are object safe.
77
78 ### Prelude
79
80 Prelude, or The Rust Prelude, is a small collection of items - mostly traits - that are
81 imported into every module of every crate. The traits in the prelude are pervasive.
82
83 ### Size
84
85 The size of a value has two definitions.
86
87 The first is that it is how much memory must be allocated to store that value.
88
89 The second is that it is the offset in bytes between successive elements in an
90 array with that item type.
91
92 It is a multiple of the alignment, including zero. The size can change
93 depending on compiler version (as new optimizations are made) and target
94 platform (similar to how `usize` varies per-platform).
95
96 [More][alignment].
97
98 ### Slice
99
100 A slice is dynamically-sized view into a contiguous sequence, written as `[T]`.
101
102 It is often seen in its borrowed forms, either mutable or shared. The shared
103 slice type is `&[T]`, while the mutable slice type is `&mut [T]`, where `T` represents
104 the element type.
105
106 ### Statement
107
108 A statement is the smallest standalone element of a programming language
109 that commands a computer to perform an action.
110
111 ### String literal
112
113 A string literal is a string stored directly in the final binary, and so will be
114 valid for the `'static` duration.
115
116 Its type is `'static` duration borrowed string slice, `&'static str`.
117
118 ### String slice
119
120 A string slice is the most primitive string type in Rust, written as `str`. It is
121 often seen in its borrowed forms, either mutable or shared. The shared
122 string slice type is `&str`, while the mutable string slice type is `&mut str`.
123
124 Strings slices are always valid UTF-8.
125
126 ### Trait
127
128 A trait is a language item that is used for describing the functionalities a type must provide.
129 It allows a type to make certain promises about its behavior.
130
131 Generic functions and generic structs can use traits to constrain, or bound, the types they accept.
132
133 [alignment]: type-layout.html#size-and-alignment
134 [enums]: items/enumerations.html
135 [structs]: items/structs.html
136 [unions]: items/unions.html
137 [trait objects]: types.html#trait-objects
138 [implementations]: items/implementations.html
139 [traits]: items/traits.html
140 [object safety]: items/traits.html#object-safety