mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-24 01:52:27 +00:00
Add conditional DerefMut for UniquePtr
This commit is contained in:
parent
da55763434
commit
300ef4a0f4
@ -6,7 +6,7 @@ use core::ffi::c_void;
|
||||
use core::fmt::{self, Debug, Display};
|
||||
use core::marker::PhantomData;
|
||||
use core::mem;
|
||||
use core::ops::Deref;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::pin::Pin;
|
||||
use core::ptr;
|
||||
|
||||
@ -119,6 +119,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for UniquePtr<T>
|
||||
where
|
||||
T: UniquePtrTarget + Unpin,
|
||||
{
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
match self.as_mut() {
|
||||
Some(target) => Pin::into_inner(target),
|
||||
None => panic!("called deref_mut on a null UniquePtr<{}>", T::__NAME),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for UniquePtr<T>
|
||||
where
|
||||
T: Debug + UniquePtrTarget,
|
||||
|
@ -1,11 +1,3 @@
|
||||
error[E0596]: cannot borrow data in a dereference of `UniquePtr<Shared>` as mutable
|
||||
--> $DIR/unique_ptr_as_mut.rs:19:31
|
||||
|
|
||||
19 | let _: &mut ffi::Shared = &mut shared;
|
||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
|
||||
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `UniquePtr<Shared>`
|
||||
|
||||
error[E0596]: cannot borrow data in a dereference of `UniquePtr<ffi::Opaque>` as mutable
|
||||
--> $DIR/unique_ptr_as_mut.rs:22:31
|
||||
|
|
||||
|
Loading…
x
Reference in New Issue
Block a user