Question: I'm trying to copy a slice from a raw pointer into a new slice `ss`:

```
pub fn receive(&mut self, data: *const u8, len: usize) {
        let s = unsafe{slice::from_raw_parts(data, len)};
        let mut ss = [0, len];
        ss.copy_from_slice(s);
        self.received.lock().unwrap().push_back(ss);
}

```

but I'm having trouble creating this new slice. I tried to give the lenght `len` so it's compatible with slice `s` but I do not understand what's happening

Answer: 
> 
> I'm trying to copy a slice from a raw pointer into a new slice `ss`:
> 
> 
> 

There is no such thing as a "new slice", a slice always points to memory from something else. If you want to copy an existing slice to a new location, you will need to allocate the data for that location, e.g. using a `Vec`:

```rust
let mut ss = vec![0; len];
ss.copy_from_slice(s);

```

However, since you already have a slice (`s`) and the `push_back` method of `self.received` accepts a slice, why not avoid the copying and simply call `self.received.lock().unwrap().push_back(s)`?
Providing error messages is usually helpful to help diagnose issues. Providing an immediately usable reproduction of the issue (e.g. something on the playground) is also useful.

Anyway cutting down on the things we can't know and don't care about in your function we get this:

```rust
use std::slice;

fn receive(data: *const u8, len: usize) {
    let s = unsafe{slice::from_raw_parts(data, len)};
    let mut ss = [0, len];
    ss.copy_from_slice(s);
}

```

Compiling yields the following:

```
error[E0308]: mismatched types
 --> src/lib.rs:6:28
  |
6 |         ss.copy_from_slice(s);
  |                            ^ expected `usize`, found `u8`
  |
  = note: expected reference `&[usize]`
             found reference `&[u8]`

```

So `ss` is a `&[usize]` instead of an `&[u8]`. Weird. Let's explicitly type `ss` as an `&[u8]` to try and force it then:

```
error[E0308]: mismatched types
 --> src/lib.rs:5:25
  |
5 |     let mut ss: &[u8] = [0, len];
  |                 -----   ^^^^^^^^ expected `&[u8]`, found array `[usize; 2]`
  |                 |
  |                 expected due to this

```

Well there's the issue: `[0, len]` is not a slice. It's an array of length 2 containing the two elements `0` and whatever `len` is (and since `len` is `usize` it's an `[usize;2]`. A slice literal is `&[]`, and neither arrays nor slice literals can take a runtime length, the length needs to be known at compile-time.

And even if you do make it a slice, you probably won't be able to push it into `received`, because the slice just refers to data local to the function, it won't be able to escape.

You might want a Vec.