1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta name ="generator " content ="rustdoc ">
7
+ < meta name ="description " content ="API documentation for the Rust `arc` mod in crate `alloc`. ">
8
+ < meta name ="keywords " content ="rust, rustlang, rust-lang, arc ">
9
+
10
+ < title > alloc::arc - Rust</ title >
11
+
12
+ < link rel ="stylesheet " type ="text/css " href ="../../rustdoc.css ">
13
+ < link rel ="stylesheet " type ="text/css " href ="../../main.css ">
14
+
15
+ < link rel ="shortcut icon " href ="https://doc.rust-lang.org/favicon.ico ">
16
+
17
+ </ head >
18
+ < body class ="rustdoc ">
19
+ <!--[if lte IE 8]>
20
+ <div class="warning">
21
+ This old browser is unsupported and will most likely display funky
22
+ things.
23
+ </div>
24
+ <![endif]-->
25
+
26
+
27
+
28
+ < nav class ="sidebar ">
29
+ < a href ='../../alloc/index.html '> < img src ='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png ' alt ='' width ='100 '> </ a >
30
+ < p class ='location '> < a href ='../index.html '> alloc</ a > </ p > < script > window . sidebarCurrent = { name : 'arc' , ty : 'mod' , relpath : '../' } ; </ script > < script defer src ="../sidebar-items.js "> </ script >
31
+ </ nav >
32
+
33
+ < nav class ="sub ">
34
+ < form class ="search-form js-only ">
35
+ < div class ="search-container ">
36
+ < input class ="search-input " name ="search "
37
+ autocomplete ="off "
38
+ placeholder ="Click or press ‘S’ to search, ‘?’ for more options… "
39
+ type ="search ">
40
+ </ div >
41
+ </ form >
42
+ </ nav >
43
+
44
+ < section id ='main ' class ="content mod ">
45
+ < h1 class ='fqn '> < span class ='in-band '> Module < a href ='../index.html '> alloc</ a > ::< wbr > < a class ='mod ' href =''> arc</ a > </ span > < span class ='out-of-band '> < span id ='render-detail '>
46
+ < a id ="toggle-all-docs " href ="javascript:void(0) " title ="collapse all docs ">
47
+ [< span class ='inner '> −</ span > ]
48
+ </ a >
49
+ </ span > < a id ='src-331 ' class ='srclink ' href ='../../src/alloc/arc.rs.html#11-1184 ' title ='goto source code '> [src]</ a > </ span > </ h1 >
50
+ < div class ='docblock '> < p > Threadsafe reference-counted boxes (the < code > Arc<T></ code > type).</ p >
51
+
52
+ < p > The < code > Arc<T></ code > type provides shared ownership of an immutable value.
53
+ Destruction is deterministic, and will occur as soon as the last owner is
54
+ gone. It is marked as < code > Send</ code > because it uses atomic reference counting.</ p >
55
+
56
+ < p > If you do not need thread-safety, and just need shared ownership, consider
57
+ the < a href ="../rc/struct.Rc.html "> < code > Rc<T></ code > type</ a > . It is the same as < code > Arc<T></ code > , but
58
+ does not use atomics, making it both thread-unsafe as well as significantly
59
+ faster when updating the reference count.</ p >
60
+
61
+ < p > The < code > downgrade</ code > method can be used to create a non-owning < code > Weak<T></ code > pointer
62
+ to the box. A < code > Weak<T></ code > pointer can be upgraded to an < code > Arc<T></ code > pointer, but
63
+ will return < code > None</ code > if the value has already been dropped.</ p >
64
+
65
+ < p > For example, a tree with parent pointers can be represented by putting the
66
+ nodes behind strong < code > Arc<T></ code > pointers, and then storing the parent pointers
67
+ as < code > Weak<T></ code > pointers.</ p >
68
+
69
+ < h1 id ='examples ' class ='section-header '> < a href ='#examples '> Examples</ a > </ h1 >
70
+ < p > Sharing some immutable data between threads:</ p >
71
+ < pre class ='rust rust-example-rendered '>
72
+ < span class ='kw '> use</ span > < span class ='ident '> std</ span > ::< span class ='ident '> sync</ span > ::< span class ='ident '> Arc</ span > ;
73
+ < span class ='kw '> use</ span > < span class ='ident '> std</ span > ::< span class ='ident '> thread</ span > ;
74
+
75
+ < span class ='kw '> let</ span > < span class ='ident '> five</ span > < span class ='op '> =</ span > < span class ='ident '> Arc</ span > ::< span class ='ident '> new</ span > (< span class ='number '> 5</ span > );
76
+
77
+ < span class ='kw '> for</ span > _ < span class ='kw '> in</ span > < span class ='number '> 0</ span > ..< span class ='number '> 10</ span > {
78
+ < span class ='kw '> let</ span > < span class ='ident '> five</ span > < span class ='op '> =</ span > < span class ='ident '> five</ span > .< span class ='ident '> clone</ span > ();
79
+
80
+ < span class ='ident '> thread</ span > ::< span class ='ident '> spawn</ span > (< span class ='kw '> move</ span > < span class ='op '> ||</ span > {
81
+ < span class ='macro '> println</ span > < span class ='macro '> !</ span > (< span class ='string '> "{:?}"</ span > , < span class ='ident '> five</ span > );
82
+ });
83
+ }</ pre >
84
+
85
+ < p > Sharing mutable data safely between threads with a < code > Mutex</ code > :</ p >
86
+ < pre class ='rust rust-example-rendered '>
87
+ < span class ='kw '> use</ span > < span class ='ident '> std</ span > ::< span class ='ident '> sync</ span > ::{< span class ='ident '> Arc</ span > , < span class ='ident '> Mutex</ span > };
88
+ < span class ='kw '> use</ span > < span class ='ident '> std</ span > ::< span class ='ident '> thread</ span > ;
89
+
90
+ < span class ='kw '> let</ span > < span class ='ident '> five</ span > < span class ='op '> =</ span > < span class ='ident '> Arc</ span > ::< span class ='ident '> new</ span > (< span class ='ident '> Mutex</ span > ::< span class ='ident '> new</ span > (< span class ='number '> 5</ span > ));
91
+
92
+ < span class ='kw '> for</ span > _ < span class ='kw '> in</ span > < span class ='number '> 0</ span > ..< span class ='number '> 10</ span > {
93
+ < span class ='kw '> let</ span > < span class ='ident '> five</ span > < span class ='op '> =</ span > < span class ='ident '> five</ span > .< span class ='ident '> clone</ span > ();
94
+
95
+ < span class ='ident '> thread</ span > ::< span class ='ident '> spawn</ span > (< span class ='kw '> move</ span > < span class ='op '> ||</ span > {
96
+ < span class ='kw '> let</ span > < span class ='kw-2 '> mut</ span > < span class ='ident '> number</ span > < span class ='op '> =</ span > < span class ='ident '> five</ span > .< span class ='ident '> lock</ span > ().< span class ='ident '> unwrap</ span > ();
97
+
98
+ < span class ='op '> *</ span > < span class ='ident '> number</ span > < span class ='op '> +=</ span > < span class ='number '> 1</ span > ;
99
+
100
+ < span class ='macro '> println</ span > < span class ='macro '> !</ span > (< span class ='string '> "{}"</ span > , < span class ='op '> *</ span > < span class ='ident '> number</ span > ); < span class ='comment '> // prints 6</ span >
101
+ });
102
+ }</ pre >
103
+ </ div > < h2 id ='structs ' class ='section-header '> < a href ="#structs "> Structs</ a > </ h2 >
104
+ < table >
105
+ < tr class =' module-item '>
106
+ < td > < a class ='struct ' href ='struct.Arc.html '
107
+ title ='alloc::arc::Arc '> Arc</ a > </ td >
108
+ < td class ='docblock short '>
109
+ < p > An atomically reference counted wrapper for shared state.</ p >
110
+
111
+ </ td >
112
+ </ tr >
113
+
114
+ < tr class =' module-item '>
115
+ < td > < a class ='struct ' href ='struct.Weak.html '
116
+ title ='alloc::arc::Weak '> Weak</ a > </ td >
117
+ < td class ='docblock short '>
118
+ < p > A weak pointer to an < code > Arc</ code > .</ p >
119
+
120
+ </ td >
121
+ </ tr >
122
+ </ table > </ section >
123
+ < section id ='search ' class ="content hidden "> </ section >
124
+
125
+ < section class ="footer "> </ section >
126
+
127
+ < aside id ="help " class ="hidden ">
128
+ < div >
129
+ < h1 class ="hidden "> Help</ h1 >
130
+
131
+ < div class ="shortcuts ">
132
+ < h2 > Keyboard Shortcuts</ h2 >
133
+
134
+ < dl >
135
+ < dt > ?</ dt >
136
+ < dd > Show this help dialog</ dd >
137
+ < dt > S</ dt >
138
+ < dd > Focus the search field</ dd >
139
+ < dt > ⇤</ dt >
140
+ < dd > Move up in search results</ dd >
141
+ < dt > ⇥</ dt >
142
+ < dd > Move down in search results</ dd >
143
+ < dt > ⏎</ dt >
144
+ < dd > Go to active search result</ dd >
145
+ </ dl >
146
+ </ div >
147
+
148
+ < div class ="infos ">
149
+ < h2 > Search Tricks</ h2 >
150
+
151
+ < p >
152
+ Prefix searches with a type followed by a colon (e.g.
153
+ < code > fn:</ code > ) to restrict the search to a given type.
154
+ </ p >
155
+
156
+ < p >
157
+ Accepted types are: < code > fn</ code > , < code > mod</ code > ,
158
+ < code > struct</ code > , < code > enum</ code > ,
159
+ < code > trait</ code > , < code > type</ code > , < code > macro</ code > ,
160
+ and < code > const</ code > .
161
+ </ p >
162
+
163
+ < p >
164
+ Search functions by type signature (e.g.
165
+ < code > vec -> usize</ code > )
166
+ </ p >
167
+ </ div >
168
+ </ div >
169
+ </ aside >
170
+
171
+
172
+
173
+ < script >
174
+ window . rootPath = "../../" ;
175
+ window . currentCrate = "alloc" ;
176
+ window . playgroundUrl = "" ;
177
+ </ script >
178
+ < script src ="../../jquery.js "> </ script >
179
+ < script src ="../../main.js "> </ script >
180
+
181
+ < script defer src ="../../search-index.js "> </ script >
182
+ </ body >
183
+ </ html >
0 commit comments