opencv_binding_generator/settings/
func_inject.rs1use crate::class::ClassDesc;
2use crate::field::{Field, FieldDesc};
3use crate::func::FuncKind::{Constructor, InstanceMethod};
4use crate::func::ReturnKind::{Fallible, InfallibleNaked};
5use crate::func::{FuncCppBody, FuncDesc};
6use crate::type_ref::Constness::{Const, Mut};
7use crate::type_ref::{TypeRef, TypeRefDesc, TypeRefTypeHint};
8use crate::writer::rust_native::type_ref::Lifetime;
9use crate::{Func, SupportedModule};
10
11pub type FuncInject = Vec<FuncFactory>;
12
13pub type FuncFactory = fn() -> Func<'static, 'static>;
14
15pub fn func_inject_factory(module: SupportedModule) -> FuncInject {
16 match module {
17 SupportedModule::Core => vec![
18 || {
19 Func::new_desc(
20 FuncDesc::new(
21 InstanceMethod(ClassDesc::cv_matconstiterator()),
22 Const,
23 InfallibleNaked,
24 "type",
25 SupportedModule::Core,
26 [],
27 TypeRefDesc::int(),
28 )
29 .cpp_body(FuncCppBody::ManualCall("instance->m->type()".into())),
30 )
31 },
32 || {
33 Func::new_desc(FuncDesc::new(
34 InstanceMethod(ClassDesc::cv_mat()),
35 Const,
36 Fallible,
37 "size",
38 SupportedModule::Core,
39 [],
40 TypeRefDesc::cv_size(),
41 ))
42 },
43 || {
44 Func::new_desc(
45 FuncDesc::new(
46 InstanceMethod(ClassDesc::cv_mat()),
47 Const,
48 Fallible,
49 "getDataDump",
50 SupportedModule::Core,
51 [],
52 TypeRefDesc::std_string(),
53 )
54 .cpp_body(FuncCppBody::ManualCall(
55 "std::string();\nstd::ostringstream oss;\noss << *instance;\nret = oss.str()".into(),
56 ))
57 .doc_comment("Return the dump of the Mat's data"),
58 )
59 },
60 || {
61 Func::new_desc(FuncDesc::new(
62 InstanceMethod(ClassDesc::cv_umat()),
63 Const,
64 Fallible,
65 "size",
66 SupportedModule::Core,
67 [],
68 TypeRefDesc::cv_size(),
69 ))
70 },
71 || {
72 Func::new_desc(
73 FuncDesc::new(
74 Constructor(ClassDesc::cv_input_array()),
75 Mut,
76 Fallible,
77 "_InputArray",
78 SupportedModule::Core,
79 [
80 Field::new_desc(FieldDesc::new(
81 "vec",
82 TypeRef::new_array(TypeRefDesc::uchar().with_inherent_constness(Const), None),
83 )),
84 Field::new_desc(FieldDesc::new(
85 "n",
86 TypeRefDesc::int().with_type_hint(TypeRefTypeHint::LenForSlice(["vec".to_string()].into(), 1)),
87 )),
88 ],
89 TypeRefDesc::cv_input_array()
90 .with_inherent_constness(Const)
91 .with_type_hint(TypeRefTypeHint::BoxedAsRef(Const, &["vec"], Lifetime::Elided)),
92 )
93 .rust_custom_leafname("from_byte_slice"),
94 )
95 },
96 ],
97 _ => vec![],
98 }
99}