diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-06-02 19:03:28 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-06-02 19:14:57 -0700 |
| commit | 3f6e6532ac17e97ce48b91e07340361a32ef480b (patch) | |
| tree | 8aba1f764b51f07fad2f41a67adbdae980023eb4 /src/libcore/ptr.rs | |
| parent | e94683dce9832dddf5af5c5ffd1384c7fd113729 (diff) | |
make vec fns/methods take imm slices.
this also repairs the unsoundness in typing of unpack_slice, which was silently converting a const ptr to an imm one.
Diffstat (limited to 'src/libcore/ptr.rs')
| -rw-r--r-- | src/libcore/ptr.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index eac3ed27934..e83c35f5ed8 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -3,6 +3,7 @@ export addr_of; export mut_addr_of; export offset; +export const_offset; export mut_offset; export null; export is_null; @@ -45,6 +46,12 @@ fn offset<T>(ptr: *T, count: uint) -> *T unsafe { (ptr as uint + count * sys::size_of::<T>()) as *T } +#[doc = "Calculate the offset from a const pointer"] +#[inline(always)] +fn const_offset<T>(ptr: *const T, count: uint) -> *const T unsafe { + (ptr as uint + count * sys::size_of::<T>()) as *T +} + #[doc = "Calculate the offset from a mut pointer"] #[inline(always)] fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T { |
