]>
git.proxmox.com Git - rustc.git/blob - vendor/tendril/src/util.rs
1 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
4 // option. This file may not be copied, modified, or distributed
5 // except according to those terms.
11 pub unsafe fn unsafe_slice
<'a
>(buf
: &'a
[u8], start
: usize, new_len
: usize) -> &'a
[u8] {
12 debug_assert
!(start
<= buf
.len());
13 debug_assert
!(new_len
<= (buf
.len() - start
));
14 slice
::from_raw_parts(buf
.as_ptr().offset(start
as isize), new_len
)
18 pub unsafe fn unsafe_slice_mut
<'a
>(
23 debug_assert
!(start
<= buf
.len());
24 debug_assert
!(new_len
<= (buf
.len() - start
));
25 slice
::from_raw_parts_mut(buf
.as_mut_ptr().offset(start
as isize), new_len
)
29 pub unsafe fn copy_and_advance(dest
: &mut *mut u8, src
: &[u8]) {
30 ptr
::copy_nonoverlapping(src
.as_ptr(), *dest
, src
.len());
31 *dest
= dest
.offset(src
.len() as isize)
35 pub unsafe fn copy_lifetime_mut
<'a
, S
: ?Sized
, T
: ?Sized
+ 'a
>(
43 pub unsafe fn copy_lifetime
<'a
, S
: ?Sized
, T
: ?Sized
+ 'a
>(_ptr
: &'a S
, ptr
: &T
) -> &'a T
{