Skip to content

Commit 54d21e1

Browse files
committed
Show Mat data dump in Debug implementation
1 parent 9cede83 commit 54d21e1

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

binding-generator/src/class/desc.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::rc::Rc;
22

3-
use crate::element::ExcludeKind;
4-
53
use super::{Class, ClassKind, TemplateKind};
4+
use crate::element::ExcludeKind;
65

76
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
87
pub struct ClassDesc<'tu, 'ge> {
@@ -114,6 +113,11 @@ impl<'tu, 'ge> ClassDesc<'tu, 'ge> {
114113
Class::new_desc(Self::system("cv::String", "core"))
115114
}
116115

116+
/// `std::String`
117+
pub fn std_string() -> Class<'tu, 'ge> {
118+
Class::new_desc(Self::system("std::string", "core"))
119+
}
120+
117121
/// `cv::MatConstIterator`
118122
pub fn cv_matconstiterator() -> Class<'tu, 'ge> {
119123
Class::new_desc(Self::boxed("cv::MatConstIterator", "core"))

binding-generator/src/settings/func_inject.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::class::ClassDesc;
22
use crate::field::{Field, FieldDesc};
3-
use crate::func::{FuncCppBody, FuncDesc, FuncKind, FuncRustBody, ReturnKind};
3+
use crate::func::FuncKind::{Constructor, InstanceMethod};
4+
use crate::func::ReturnKind::{Fallible, InfallibleNaked};
5+
use crate::func::{FuncCppBody, FuncDesc, FuncRustBody};
46
use crate::type_ref::Constness::{Const, Mut};
57
use crate::type_ref::{TypeRef, TypeRefDesc, TypeRefTypeHint};
68
use crate::writer::rust_native::type_ref::Lifetime;
@@ -13,9 +15,9 @@ pub fn func_inject_factory(module: &str) -> Vec<FuncFactory> {
1315
"core" => vec![
1416
(|| {
1517
Func::new_desc(FuncDesc::new(
16-
FuncKind::InstanceMethod(ClassDesc::cv_matconstiterator()),
18+
InstanceMethod(ClassDesc::cv_matconstiterator()),
1719
Const,
18-
ReturnKind::InfallibleNaked,
20+
InfallibleNaked,
1921
"type",
2022
"core",
2123
vec![],
@@ -26,9 +28,9 @@ pub fn func_inject_factory(module: &str) -> Vec<FuncFactory> {
2628
}) as FuncFactory, // todo: remove this cast when MSRV allows
2729
|| {
2830
Func::new_desc(FuncDesc::new(
29-
FuncKind::InstanceMethod(ClassDesc::cv_mat()),
31+
InstanceMethod(ClassDesc::cv_mat()),
3032
Const,
31-
ReturnKind::Fallible,
33+
Fallible,
3234
"size",
3335
"core",
3436
vec![],
@@ -39,9 +41,22 @@ pub fn func_inject_factory(module: &str) -> Vec<FuncFactory> {
3941
},
4042
|| {
4143
Func::new_desc(FuncDesc::new(
42-
FuncKind::InstanceMethod(ClassDesc::cv_umat()),
44+
InstanceMethod(ClassDesc::cv_mat()),
4345
Const,
44-
ReturnKind::Fallible,
46+
Fallible,
47+
"getDataDump",
48+
"core",
49+
vec![],
50+
FuncCppBody::ManualCall("std::string();\nstd::ostringstream oss;\noss << *instance;\nret = oss.str()".into()),
51+
FuncRustBody::Auto,
52+
TypeRefDesc::std_string(),
53+
))
54+
},
55+
|| {
56+
Func::new_desc(FuncDesc::new(
57+
InstanceMethod(ClassDesc::cv_umat()),
58+
Const,
59+
Fallible,
4560
"size",
4661
"core",
4762
vec![],
@@ -52,9 +67,9 @@ pub fn func_inject_factory(module: &str) -> Vec<FuncFactory> {
5267
},
5368
|| {
5469
Func::new_desc(FuncDesc::new(
55-
FuncKind::Constructor(ClassDesc::cv_input_array()),
70+
Constructor(ClassDesc::cv_input_array()),
5671
Mut,
57-
ReturnKind::Fallible,
72+
Fallible,
5873
"_InputArray",
5974
"core",
6075
vec![

binding-generator/src/type_ref/desc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ impl<'tu, 'ge> TypeRefDesc<'tu, 'ge> {
211211
TypeRef::new_class(ClassDesc::cv_string())
212212
}
213213

214+
/// `std::string`
215+
pub fn std_string() -> TypeRef<'tu, 'ge> {
216+
TypeRef::new_class(ClassDesc::std_string())
217+
}
218+
214219
/// `std::vector<std::vector<double>>`
215220
pub fn vector_of_vector_of_double() -> TypeRef<'tu, 'ge> {
216221
TypeRef::new_vector(Vector::new_desc(VectorDesc::new(TypeRef::new_vector(Vector::new_desc(

src/manual/core/mat.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,19 @@ impl fmt::Debug for Mat {
788788
.field("total", &self.total())
789789
.field("is_continuous", &self.is_continuous())
790790
.field("is_submatrix", &self.is_submatrix())
791+
.field("data", &MatDataDumper(self))
791792
.finish()
792793
}
793794
}
794795

796+
struct MatDataDumper<'r>(&'r Mat);
797+
798+
impl fmt::Debug for MatDataDumper<'_> {
799+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
800+
f.write_str(&self.0.get_data_dump().map_err(|_| fmt::Error)?)
801+
}
802+
}
803+
795804
input_output_array! { UMat, from_umat, from_umat_mut }
796805
input_output_array_vector! { UMat, from_umat_vec, from_umat_vec_mut }
797806

0 commit comments

Comments
 (0)