Skip to content

Commit 88f59d9

Browse files
committed
Move opencv_type_simple_generic to opencv_type module
1 parent dd5cd5f commit 88f59d9

File tree

8 files changed

+52
-35
lines changed

8 files changed

+52
-35
lines changed

src/manual/core.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,6 @@ macro_rules! valid_types {
2929
};
3030
}
3131

32-
macro_rules! opencv_type_simple_generic {
33-
($type: ident<$trait: ident>) => {
34-
impl<T: $trait> $crate::traits::OpenCVType<'_> for $type<T> {
35-
type Arg = Self;
36-
type ExternReceive = Self;
37-
type ExternContainer = Self;
38-
39-
#[inline] fn opencv_into_extern_container(self) -> $crate::Result<Self> { Ok(self) }
40-
#[inline] fn opencv_into_extern_container_nofail(self) -> Self { self }
41-
#[inline] unsafe fn opencv_from_extern(s: Self) -> Self { s }
42-
}
43-
44-
impl<T: $trait> $crate::traits::OpenCVTypeArg<'_> for $type<T> {
45-
type ExternContainer = Self;
46-
47-
#[inline] fn opencv_into_extern_container(self) -> $crate::Result<Self> { Ok(self) }
48-
#[inline] fn opencv_into_extern_container_nofail(self) -> Self { self }
49-
}
50-
51-
impl<T: $trait> $crate::traits::OpenCVTypeExternContainer for $type<T> {
52-
type ExternSend = *const Self;
53-
type ExternSendMut = *mut Self;
54-
55-
#[inline] fn opencv_as_extern(&self) -> Self::ExternSend { self }
56-
#[inline] fn opencv_as_extern_mut(&mut self) -> Self::ExternSendMut { self }
57-
#[inline] fn opencv_into_extern(self) -> Self::ExternSendMut { &mut *std::mem::ManuallyDrop::new(self) as _ }
58-
}
59-
};
60-
}
61-
6232
mod affine3;
6333
mod gpumat;
6434
mod input_output_array;

src/manual/core/affine3.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::core::{Matx44, ValidMatxType, MatxTrait};
1+
use crate::{
2+
core::{Matx44, MatxTrait, ValidMatxType},
3+
opencv_type_simple_generic,
4+
};
25

36
/// [docs.opencv.org](https://docs.opencv.org/master/dd/d99/classcv_1_1Affine3.html)
47
#[repr(C)]

src/manual/core/point.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
22

33
use num_traits::{NumCast, ToPrimitive};
44

5-
use crate::core::{Rect_, Size_, ValidRectType, ValidSizeType, ValidVecType, Vec2};
5+
use crate::{
6+
core::{Rect_, Size_, ValidRectType, ValidSizeType, ValidVecType, Vec2},
7+
opencv_type_simple_generic,
8+
};
69

710
valid_types!(ValidPointType: i32, i64, f32, f64);
811

src/manual/core/point3.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
22

33
use num_traits::{NumCast, ToPrimitive, Zero};
44

5-
use crate::core::{Point_, ValidPointType, ValidVecType, Vec3};
5+
use crate::{
6+
core::{Point_, ValidPointType, ValidVecType, Vec3},
7+
opencv_type_simple_generic,
8+
};
69

710
valid_types!(ValidPoint3Type: i32, f32, f64);
811

src/manual/core/rect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
66

77
use num_traits::{NumCast, ToPrimitive};
88

9-
use crate::core::{Point_, prelude::*, RotatedRect, Size_, ValidPointType, ValidSizeType};
9+
use crate::{
10+
core::{Point_, prelude::*, RotatedRect, Size_, ValidPointType, ValidSizeType},
11+
opencv_type_simple_generic,
12+
};
1013

1114
valid_types!(ValidRectType: i32, f32, f64);
1215

src/manual/core/size.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
22

33
use num_traits::{NumCast, ToPrimitive};
44

5-
use crate::core::{Point_, ValidPointType};
5+
use crate::{
6+
core::{Point_, ValidPointType},
7+
opencv_type_simple_generic,
8+
};
69

710
valid_types!(ValidSizeType: i32, i64, f32, f64);
811

src/manual/core/vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::ffi::c_void;
22

33
use crate::{
44
core::{_InputArray, ToInputArray},
5+
opencv_type_simple_generic,
56
Result,
67
sys,
78
traits::Boxed,

src/traits/opencv_type.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,37 @@ macro_rules! opencv_type_simple {
140140
};
141141
}
142142

143+
#[macro_export]
144+
macro_rules! opencv_type_simple_generic {
145+
($type: ident<$trait: ident>) => {
146+
impl<T: $trait> $crate::traits::OpenCVType<'_> for $type<T> {
147+
type Arg = Self;
148+
type ExternReceive = Self;
149+
type ExternContainer = Self;
150+
151+
#[inline] fn opencv_into_extern_container(self) -> $crate::Result<Self> { Ok(self) }
152+
#[inline] fn opencv_into_extern_container_nofail(self) -> Self { self }
153+
#[inline] unsafe fn opencv_from_extern(s: Self) -> Self { s }
154+
}
155+
156+
impl<T: $trait> $crate::traits::OpenCVTypeArg<'_> for $type<T> {
157+
type ExternContainer = Self;
158+
159+
#[inline] fn opencv_into_extern_container(self) -> $crate::Result<Self> { Ok(self) }
160+
#[inline] fn opencv_into_extern_container_nofail(self) -> Self { self }
161+
}
162+
163+
impl<T: $trait> $crate::traits::OpenCVTypeExternContainer for $type<T> {
164+
type ExternSend = *const Self;
165+
type ExternSendMut = *mut Self;
166+
167+
#[inline] fn opencv_as_extern(&self) -> Self::ExternSend { self }
168+
#[inline] fn opencv_as_extern_mut(&mut self) -> Self::ExternSendMut { self }
169+
#[inline] fn opencv_into_extern(self) -> Self::ExternSendMut { &mut *std::mem::ManuallyDrop::new(self) as _ }
170+
}
171+
};
172+
}
173+
143174
pub fn cstring_new_nofail(bytes: impl Into<Vec<u8>>) -> CString {
144175
match CString::new(bytes) {
145176
Ok(s) => {

0 commit comments

Comments
 (0)