opencv_binding_generator/settings/
property_tweaks.rs

1use std::collections::HashMap;
2
3pub type PropertyTweaks = HashMap<&'static str, PropertyTweak<'static>>;
4
5#[derive(Debug)]
6pub struct PropertyTweak<'l> {
7	pub rename: Option<&'l str>,
8	pub read_write: Option<PropertyReadWrite>,
9}
10
11/// Rename property, format: (cpp_refname -> rust_custom_leafname)
12pub fn property_tweaks_factory(module: &str) -> PropertyTweaks {
13	match module {
14		"core" => HashMap::from([
15			(
16				"cv::Mat::size",
17				PropertyTweak {
18					rename: Some("mat_size"),
19					..PropertyTweak::none()
20				},
21			),
22			(
23				"cv::Mat::step",
24				PropertyTweak {
25					rename: Some("mat_step"),
26					read_write: Some(PropertyReadWrite::ReadOnly), // MatStep type prevents assignment
27				},
28			),
29			(
30				"cv::UMat::size",
31				PropertyTweak {
32					rename: Some("mat_size"),
33					..PropertyTweak::none()
34				},
35			),
36			(
37				"cv::UMat::step",
38				PropertyTweak {
39					rename: Some("mat_step"),
40					read_write: Some(PropertyReadWrite::ReadOnly), // MatStep type prevents assignment
41				},
42			),
43		]),
44		_ => HashMap::new(),
45	}
46}
47
48impl PropertyTweak<'_> {
49	pub fn none() -> PropertyTweak<'static> {
50		PropertyTweak {
51			rename: None,
52			read_write: None,
53		}
54	}
55}
56
57#[derive(Clone, Copy, Debug)]
58pub enum PropertyReadWrite {
59	ReadOnly,
60	ReadWrite,
61}
62
63impl PropertyReadWrite {
64	pub fn is_read(self) -> bool {
65		match self {
66			PropertyReadWrite::ReadOnly | PropertyReadWrite::ReadWrite => true,
67		}
68	}
69
70	pub fn is_write(self) -> bool {
71		match self {
72			PropertyReadWrite::ReadWrite => true,
73			PropertyReadWrite::ReadOnly => false,
74		}
75	}
76}