You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fact that the lifetime of the returned slice is the same as the lifetime of the pointer is a very bad idea. And now that CVec is gone, this is the only way to build a slice from a raw pointer.
I can see many potential problems, but the ones that I've encountered while removing CVec is that you can't cast your pointers, not even from mut to const: (http://is.gd/eW1KmQ)
structFoo{data:*muti8,len:uint}implFoo{fnas_slice(&self) -> &[i8]{unsafe{// value "self.data as *const i8" does not live long enough
std::slice::from_raw_buf(&(self.dataas*consti8),self.len)}}}
And that you can't use raw pointers in iterators anymore: (http://is.gd/UsePsX)
structIter<'a>{data:*constu8,marker:ContravariantLifetime<'a>}impl<'a>IteratorforIter<'a>{typeItem = &'a[u8];fnnext(&mutself) -> Option<&'a[u8]>{Some(unsafe{// cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
std::slice::from_raw_buf(&self.data,1)})}}
If I'm manipulating raw pointers which are unsafe by nature, please let me be unsafe!
The first example can be bypassed by using from_raw_mut_buf and casting the returned &mut [i8] to a &[i8], which means that the unsafe API is more restrictive than the safe API!
The text was updated successfully, but these errors were encountered:
The signature of
from_raw_buf
is:The fact that the lifetime of the returned slice is the same as the lifetime of the pointer is a very bad idea. And now that
CVec
is gone, this is the only way to build a slice from a raw pointer.I can see many potential problems, but the ones that I've encountered while removing CVec is that you can't cast your pointers, not even from mut to const: (http://is.gd/eW1KmQ)
And that you can't use raw pointers in iterators anymore: (http://is.gd/UsePsX)
If I'm manipulating raw pointers which are unsafe by nature, please let me be unsafe!
The first example can be bypassed by using
from_raw_mut_buf
and casting the returned&mut [i8]
to a&[i8]
, which means that the unsafe API is more restrictive than the safe API!The text was updated successfully, but these errors were encountered: