@@ -6,8 +6,10 @@ use crate::traits::{Boxed, OpenCVFromExtern, OpenCVIntoExternContainer, OpenCVTy
6
6
7
7
/// Wrapper for the type implementing [Boxed] trait that allows to retain the lifetime of the referenced object.
8
8
///
9
- /// This wrapper implements all traits that the underlying type does, but explicitly doesn't implement `Deref` and `DerefMut` to
10
- /// avoid being able to `mem::swap` the reference out of the wrapper.
9
+ /// This wrapper implements all traits that the underlying type does, but explicitly doesn't implement [Deref](core::ops::Deref) and
10
+ /// [DerefMut](core::ops::DerefMut) to avoid being able to [swap](core::mem::swap) the reference out of the wrapper. It relies on
11
+ /// functions accepting generic arguments (e.g. `impl MatTrait` or `impl MatTraitConst`) which are implemented by both main struct
12
+ /// and its `BoxedRef` (e.g. [Mat](crate::core::Mat) and `BoxedRef<Mat>`).
11
13
#[ repr( transparent) ]
12
14
pub struct BoxedRef < ' r , T : Boxed > {
13
15
pub ( crate ) reference : T ,
@@ -32,7 +34,7 @@ impl<T: Boxed + fmt::Debug> fmt::Debug for BoxedRef<'_, T> {
32
34
}
33
35
34
36
impl < T : Boxed + Clone > BoxedRef < ' _ , T > {
35
- /// Clones the pointee of this BoxedRef
37
+ /// Clones the pointee of this [ BoxedRef]
36
38
#[ inline]
37
39
pub fn clone_pointee ( & self ) -> T {
38
40
self . reference . clone ( )
@@ -104,13 +106,20 @@ impl<T: Boxed + fmt::Debug> fmt::Debug for BoxedRefMut<'_, T> {
104
106
}
105
107
106
108
impl < T : Boxed + Clone > BoxedRefMut < ' _ , T > {
107
- /// Clones the pointee of this BoxedRef
109
+ /// Clones the pointee of this [BoxedRefMut]
108
110
#[ inline]
109
111
pub fn clone_pointee ( & self ) -> T {
110
112
self . reference . clone ( )
111
113
}
112
114
}
113
115
116
+ impl < ' r , T : Boxed > From < BoxedRefMut < ' r , T > > for BoxedRef < ' r , T > {
117
+ /// Irreversibly convert this [BoxedRefMut] into a non-mutable [BoxedRef]
118
+ fn from ( value : BoxedRefMut < ' r , T > ) -> Self {
119
+ BoxedRef :: from ( value. reference )
120
+ }
121
+ }
122
+
114
123
impl < T : OpenCVIntoExternContainer + Boxed > OpenCVIntoExternContainer for BoxedRefMut < ' _ , T > {
115
124
type ExternContainer = T :: ExternContainer ;
116
125
0 commit comments