@@ -41,7 +41,9 @@ impl<T: VectorElement> Vector<T> where Self: VectorExtern<T> {
41
41
42
42
/// Create a Vector from iterator
43
43
pub fn from_iter < ' a > ( s : impl IntoIterator < Item =<T as OpenCVType < ' a > >:: Arg > ) -> Self {
44
- <Self as FromIterator < _ > >:: from_iter ( s)
44
+ let mut out = Self :: new ( ) ;
45
+ out. extend ( s) ;
46
+ out
45
47
}
46
48
47
49
/// Return Vector length
@@ -145,20 +147,28 @@ impl<T: VectorElement> Vector<T> where Self: VectorExtern<T> {
145
147
VectorRefIterator :: new ( self )
146
148
}
147
149
150
+ /// Return slice to the elements of the array.
151
+ ///
152
+ /// This method is only available for OpenCV types that are Copy, with the exception of bool
153
+ /// because bool is handled in a special way on the C++ side.
148
154
pub fn as_slice ( & self ) -> & [ T ] where Self : VectorExternCopyNonBool < T > {
149
155
unsafe {
150
156
slice:: from_raw_parts ( self . extern_data ( ) , self . len ( ) )
151
157
}
152
158
}
153
159
160
+ /// Return mutable slice to the elements of the array.
161
+ ///
162
+ /// This method is only available for OpenCV types that are Copy, with the exception of bool
163
+ /// because bool is handled in a special way on the C++ side.
154
164
pub fn as_mut_slice ( & mut self ) -> & mut [ T ] where Self : VectorExternCopyNonBool < T > {
155
165
unsafe {
156
166
slice:: from_raw_parts_mut ( self . extern_data_mut ( ) , self . len ( ) )
157
167
}
158
168
}
159
169
160
170
pub fn to_vec ( & self ) -> Vec < T > {
161
- T :: convert_to_vec ( self )
171
+ T :: opencv_vector_to_vec ( self )
162
172
}
163
173
}
164
174
@@ -176,11 +186,17 @@ impl<T: VectorElement> From<Vector<T>> for Vec<T> where Vector<T>: VectorExtern<
176
186
}
177
187
}
178
188
189
+ impl < T : VectorElement > From < Vec < <T as OpenCVType < ' _ > >:: Arg > > for Vector < T > where Vector < T > : VectorExtern < T > {
190
+ #[ inline]
191
+ fn from ( from : Vec < <T as OpenCVType < ' _ > >:: Arg > ) -> Self {
192
+ Self :: from_iter ( from)
193
+ }
194
+ }
195
+
179
196
impl < ' a , T : VectorElement > FromIterator < <T as OpenCVType < ' a > >:: Arg > for Vector < T > where Self : VectorExtern < T > {
197
+ #[ inline]
180
198
fn from_iter < I : IntoIterator < Item =<T as OpenCVType < ' a > >:: Arg > > ( s : I ) -> Vector < T > {
181
- let mut out = Self :: new ( ) ;
182
- out. extend ( s) ;
183
- out
199
+ Self :: from_iter ( s)
184
200
}
185
201
}
186
202
0 commit comments