@@ -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 ) {
@@ -178,6 +204,17 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
178
204
/// `src` is not used before the data is overwritten again (e.g. with `write`,
179
205
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
180
206
/// because it will attempt to drop the value previously at `*src`.
207
+ ///
208
+ /// # Examples
209
+ ///
210
+ /// Basic usage:
211
+ ///
212
+ /// ```
213
+ /// let x = 12;
214
+ /// let y = &x as *const i32;
215
+ ///
216
+ /// unsafe { println!("{}", std::ptr::read_volatile(y)); }
217
+ /// ```
181
218
#[ inline]
182
219
#[ unstable( feature = "volatile" , reason = "recently added" , issue = "31756" ) ]
183
220
pub unsafe fn read_volatile < T > ( src : * const T ) -> T {
@@ -203,6 +240,21 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
203
240
///
204
241
/// This is appropriate for initializing uninitialized memory, or overwriting
205
242
/// memory that has previously been `read` from.
243
+ ///
244
+ /// # Examples
245
+ ///
246
+ /// Basic usage:
247
+ ///
248
+ /// ```
249
+ /// let mut x = 0;
250
+ /// let y = &mut x as *mut i32;
251
+ /// let z = 12;
252
+ ///
253
+ /// unsafe {
254
+ /// std::ptr::write_volatile(y, z);
255
+ /// println!("{}", std::ptr::read_volatile(y));
256
+ /// }
257
+ /// ```
206
258
#[ inline]
207
259
#[ unstable( feature = "volatile" , reason = "recently added" , issue = "31756" ) ]
208
260
pub unsafe fn write_volatile < T > ( dst : * mut T , src : T ) {
0 commit comments