---
date: 2020-11-20
id: e3a6f28a-27fd-489d-b2b4-de6d2c149a60
title: as~ptrrange~
---
# Description
as~ptrrange~[^1] returns the two raw pointers spanning the slice.
The returned range is half-open, which means that the end pointer points
one *past* the last element of the slice. This way, an empty slice is
represented by two equal pointers, and the difference between the two
pointers represents the size of the slice.
This function is useful for interacting with foreign interfaces which
use two pointers to refer to a range of elements in memory, as is common
in C++.
# Declaration
``` rust
pub fn as_ptr_range(&self) -> Range<*const T>
```
# Traits for Range\
``` rust
impl Iterator for Range where
A: Step, type Item = A;
```
# Syntax
``` rust
#![allow(unused)]
fn main() {
let a = [1, 2, 3];
let x = &a[1] as *const _;
let y = &5 as *const _;
assert!(a.as_ptr_range().contains(&x));
assert!(!a.as_ptr_range().contains(&y));
}
```
# Footnotes
[^1]: