Add support for parsing CV_NODISCARD attribute
MODIFY
binding-generator/src/func.rs
binding-generator/src/func.rs
@@ -367,6 +367,10 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
}
}
+ pub fn is_no_discard(&self) -> bool {
+ self.gen_env.get_export_config(self.entity).map_or(false, |c| c.no_discard)
+ }
+
pub fn as_specialized(&self) -> Option<&'static HashMap<&'static str, &'static str>> {
if let FunctionTypeHint::Specialized(spec) = self.type_hint {
Some(spec)

MODIFY
binding-generator/src/generator.rs
binding-generator/src/generator.rs
@@ -262,6 +262,8 @@ impl<'tu, V: GeneratorVisitor> EntityWalkerVisitor<'tu> for OpenCvWalker<'tu, '_
self.gen_env.make_export_config(entity).no_except = true;
} else if name == "CV_DEPRECATED" || name == "CV_DEPRECATED_EXTERNAL" {
self.gen_env.make_export_config(entity).deprecated = true;
+ } else if name == "CV_NODISCARD_STD" || name == "CV_NODISCARD" {
+ self.gen_env.make_export_config(entity).no_discard = true;
} else if name == "OCVRS_ONLY_DEPENDENT_TYPES" {
self.gen_env.make_export_config(entity).only_dependent_types = true;
}

MODIFY
binding-generator/src/generator_env.rs
binding-generator/src/generator_env.rs
@@ -33,6 +33,7 @@ pub struct ExportConfig {
pub deprecated: bool,
pub no_return: bool,
pub no_except: bool,
+ pub no_discard: bool,
pub only_dependent_types: bool,
}

MODIFY
binding-generator/src/writer/rust_native/func.rs
binding-generator/src/writer/rust_native/func.rs
@@ -124,6 +124,9 @@ fn gen_rust_with_name(f: &Func, name: &str, opencv_version: &str) -> String {
if let Some(attrs) = settings::FUNC_CFG_ATTR.get(identifier.as_ref()) {
attributes = format!("#[cfg({})]", attrs.0);
}
+ if f.is_no_discard() {
+ attributes.push_str(&format!("#[must_use]"));
+ }
let tpl = if let Some(tpl) = settings::FUNC_MANUAL.get(identifier.as_ref()) {
tpl

Add support for parsing CV_NODISCARD attribute