# Struct std::raw::Slice [−] [src]

    pub struct Slice<T> {
        pub data: *const T,
        pub len: usize,
    }

Unstable (`raw` #27751)

The representation of a slice like `&[T]`.

This struct is guaranteed to have the layout of types like `&[T]`, `&str`, and `Box<[T]>`, but is not the type of such slices (e.g. the fields are not directly accessible on a `&[T]`) nor does it control that layout (changing the definition will not change the layout of a `&[T]`). It is only designed to be used by unsafe code that needs to manipulate the low-level details.

However, it is not recommended to use this type for such code, since there are alternatives which may be safer:

- Creating a slice from a data pointer and length can be done with `std::slice::from_raw_parts` or `std::slice::from_raw_parts_mut` instead of `std::mem::transmute`ing a value of type `Slice`.
- Extracting the data pointer and length from a slice can be performed with the `as_ptr` (or `as_mut_ptr`) and `len` methods.

If one does decide to convert a slice value to a `Slice`, the `Repr` trait in this module provides a method for a safe conversion from `&[T]` (and `&str`) to a `Slice`, more type-safe than a call to `transmute`.

# Examples

#![feature(raw)] fn main() { use std::raw::{self, Repr}; let slice: &[u16] = &[1, 2, 3, 4]; let repr: raw::Slice<u16> = slice.repr(); println!("data pointer = {:?}, length = {}", repr.data, repr.len); }

    #![feature(raw)]

    use std::raw::{self, Repr};

    let slice: &[u16] = &[1, 2, 3, 4];

    let repr: raw::Slice<u16> = slice.repr();
    println!("data pointer = {:?}, length = {}", repr.data, repr.len);

## Fields

`data` | Unstable (`raw` #27751)
`len` | Unstable (`raw` #27751)

## Trait Implementations

### `impl<T> Copy for Slice<T>`

### `impl<T> Clone for Slice<T>`

#### `fn clone(&self) -> Slice<T>`

#### `fn clone_from(&mut self, source: &Self)`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize`)