rust – Idiom: replace a slice with a suffix of this slice (write_all loop)

As you probably already know, the Unix I / O primitive to write is not guaranteed to write all the data in the buffer you give it; you may have to loop it over successive suffixes of the stamp until everything is gone. I'm trying to find the cleanest way to write this loop in Rust. That's what I've

use :: nix;

pub fn write_all (fd: nix :: RawFd, s: &[u8]) -> nix :: Result<()>
use :: libc :: {write, c_void};
let mut p = s;
while p.len ()> 0 {
leave consumed = dangerous {
write (fd, p.as_ptr () as * const c_void, p.len ())
if consumed < 0 {
            return Err(nix::Error::last());
        if (consumed as usize) >= p.len () {pause}
let (_, x) = p.split_at (consumed as usize);
p = x;
D & # 39; Agreement (())

It does the job, but this piece seems inelegant and I can not find a better way to write it:

                                if (consumed in the identical)> = p.len () {break}
let (_, x) = p.split_at (consumed as usize);
p = x;

the if eliminates a case of panic that should be impossible (because to write will never return a value greater than p.len ()) I could live without, but what I want to here is for split_at to give me an empty slice of leak if the split point is at or beyond the end of the entrance.

The intermediate variable X is necessary because you can not write

                                (_, p) = p.split_at (consumed as usize);

and I can not connect p directly, because the loop control expression would not see the change.

What suggestions do you have?