@@ -119,6 +119,17 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
119
119
/// `src` is not used before the data is overwritten again (e.g. with `write`,
120
120
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
121
121
/// because it will attempt to drop the value previously at `*src`.
122
+ ///
123
+ /// # Examples
124
+ ///
125
+ /// Basic usage:
126
+ ///
127
+ /// ```
128
+ /// let x = 12;
129
+ /// let y = &x as *const i32;
130
+ ///
131
+ /// unsafe { println!("{}", std::ptr::read(y)); }
132
+ /// ```
122
133
#[ inline( always) ]
123
134
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
124
135
pub unsafe fn read < T > ( src : * const T ) -> T {
@@ -155,6 +166,21 @@ pub unsafe fn read_and_drop<T>(dest: *mut T) -> T {
155
166
///
156
167
/// This is appropriate for initializing uninitialized memory, or overwriting
157
168
/// memory that has previously been `read` from.
169
+ ///
170
+ /// # Examples
171
+ ///
172
+ /// Basic usage:
173
+ ///
174
+ /// ```
175
+ /// let mut x = 0;
176
+ /// let y = &mut x as *mut i32;
177
+ /// let z = 12;
178
+ ///
179
+ /// unsafe {
180
+ /// std::ptr::write(y, z);
181
+ /// println!("{}", std::ptr::read(y));
182
+ /// }
183
+ /// ```
158
184
#[ inline]
159
185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
160
186
pub unsafe fn write < T > ( dst : * mut T , src : T ) {
@@ -185,6 +211,17 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
185
211
/// `src` is not used before the data is overwritten again (e.g. with `write`,
186
212
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
187
213
/// because it will attempt to drop the value previously at `*src`.
214
+ ///
215
+ /// # Examples
216
+ ///
217
+ /// Basic usage:
218
+ ///
219
+ /// ```
220
+ /// let x = 12;
221
+ /// let y = &x as *const i32;
222
+ ///
223
+ /// unsafe { println!("{}", std::ptr::read_volatile(y)); }
224
+ /// ```
188
225
#[ inline]
189
226
#[ stable( feature = "volatile" , since = "1.9.0" ) ]
190
227
pub unsafe fn read_volatile < T > ( src : * const T ) -> T {
@@ -217,6 +254,21 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
217
254
///
218
255
/// This is appropriate for initializing uninitialized memory, or overwriting
219
256
/// memory that has previously been `read` from.
257
+ ///
258
+ /// # Examples
259
+ ///
260
+ /// Basic usage:
261
+ ///
262
+ /// ```
263
+ /// let mut x = 0;
264
+ /// let y = &mut x as *mut i32;
265
+ /// let z = 12;
266
+ ///
267
+ /// unsafe {
268
+ /// std::ptr::write_volatile(y, z);
269
+ /// println!("{}", std::ptr::read_volatile(y));
270
+ /// }
271
+ /// ```
220
272
#[ inline]
221
273
#[ stable( feature = "volatile" , since = "1.9.0" ) ]
222
274
pub unsafe fn write_volatile < T > ( dst : * mut T , src : T ) {
0 commit comments