27
27
//! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`).
28
28
//!
29
29
//! ```
30
- //! let my_num: int = 10;
31
- //! let my_num_ptr: *const int = &my_num;
32
- //! let mut my_speed: int = 88;
33
- //! let my_speed_ptr: *mut int = &mut my_speed;
30
+ //! let my_num: i32 = 10;
31
+ //! let my_num_ptr: *const i32 = &my_num;
32
+ //! let mut my_speed: i32 = 88;
33
+ //! let my_speed_ptr: *mut i32 = &mut my_speed;
34
34
//! ```
35
35
//!
36
36
//! This does not take ownership of the original allocation
49
49
//! use std::mem;
50
50
//!
51
51
//! unsafe {
52
- //! let my_num: Box<int > = Box::new(10);
53
- //! let my_num: *const int = mem::transmute(my_num);
54
- //! let my_speed: Box<int > = Box::new(88);
55
- //! let my_speed: *mut int = mem::transmute(my_speed);
52
+ //! let my_num: Box<i32 > = Box::new(10);
53
+ //! let my_num: *const i32 = mem::transmute(my_num);
54
+ //! let my_speed: Box<i32 > = Box::new(88);
55
+ //! let my_speed: *mut i32 = mem::transmute(my_speed);
56
56
//!
57
57
//! // By taking ownership of the original `Box<T>` though
58
58
//! // we are obligated to transmute it back later to be destroyed.
59
- //! drop(mem::transmute::<_, Box<int >>(my_speed));
60
- //! drop(mem::transmute::<_, Box<int >>(my_num));
59
+ //! drop(mem::transmute::<_, Box<i32 >>(my_speed));
60
+ //! drop(mem::transmute::<_, Box<i32 >>(my_num));
61
61
//! }
62
62
//! ```
63
63
//!
73
73
//!
74
74
//! fn main() {
75
75
//! unsafe {
76
- //! let my_num: *mut int = libc::malloc(mem::size_of::<int >() as libc::size_t) as *mut int ;
76
+ //! let my_num: *mut i32 = libc::malloc(mem::size_of::<i32 >() as libc::size_t) as *mut i32 ;
77
77
//! if my_num.is_null() {
78
78
//! panic!("failed to allocate memory");
79
79
//! }
@@ -117,7 +117,7 @@ pub use intrinsics::set_memory;
117
117
/// ```
118
118
/// use std::ptr;
119
119
///
120
- /// let p: *const int = ptr::null();
120
+ /// let p: *const i32 = ptr::null();
121
121
/// assert!(p.is_null());
122
122
/// ```
123
123
#[ inline]
@@ -131,7 +131,7 @@ pub fn null<T>() -> *const T { 0 as *const T }
131
131
/// ```
132
132
/// use std::ptr;
133
133
///
134
- /// let p: *mut int = ptr::null_mut();
134
+ /// let p: *mut i32 = ptr::null_mut();
135
135
/// assert!(p.is_null());
136
136
/// ```
137
137
#[ inline]
@@ -148,7 +148,7 @@ pub fn null_mut<T>() -> *mut T { 0 as *mut T }
148
148
#[ inline]
149
149
#[ unstable( feature = "core" ,
150
150
reason = "may play a larger role in std::ptr future extensions" ) ]
151
- pub unsafe fn zero_memory < T > ( dst : * mut T , count : uint ) {
151
+ pub unsafe fn zero_memory < T > ( dst : * mut T , count : usize ) {
152
152
set_memory ( dst, 0 , count) ;
153
153
}
154
154
@@ -276,7 +276,7 @@ pub trait PtrExt: Sized {
276
276
/// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
277
277
/// the pointer is used.
278
278
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
279
- unsafe fn offset ( self , count : int ) -> Self ;
279
+ unsafe fn offset ( self , count : isize ) -> Self ;
280
280
}
281
281
282
282
/// Methods on mutable raw pointers
@@ -303,11 +303,11 @@ impl<T> PtrExt for *const T {
303
303
304
304
#[ inline]
305
305
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
306
- fn is_null ( self ) -> bool { self as uint == 0 }
306
+ fn is_null ( self ) -> bool { self as usize == 0 }
307
307
308
308
#[ inline]
309
309
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
310
- unsafe fn offset ( self , count : int ) -> * const T {
310
+ unsafe fn offset ( self , count : isize ) -> * const T {
311
311
intrinsics:: offset ( self , count)
312
312
}
313
313
@@ -330,11 +330,11 @@ impl<T> PtrExt for *mut T {
330
330
331
331
#[ inline]
332
332
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
333
- fn is_null ( self ) -> bool { self as uint == 0 }
333
+ fn is_null ( self ) -> bool { self as usize == 0 }
334
334
335
335
#[ inline]
336
336
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
337
- unsafe fn offset ( self , count : int ) -> * mut T {
337
+ unsafe fn offset ( self , count : isize ) -> * mut T {
338
338
intrinsics:: offset ( self , count) as * mut T
339
339
}
340
340
@@ -553,7 +553,7 @@ impl<T> Unique<T> {
553
553
/// Return an (unsafe) pointer into the memory owned by `self`.
554
554
#[ unstable( feature = "core" ,
555
555
reason = "recently added to this module" ) ]
556
- pub unsafe fn offset ( self , offset : int ) -> * mut T {
556
+ pub unsafe fn offset ( self , offset : isize ) -> * mut T {
557
557
self . ptr . offset ( offset)
558
558
}
559
559
}
0 commit comments