opencv_binding_generator/writer/rust_native/
abstract_ref_wrapper.rs1use std::collections::HashMap;
2
3use once_cell::sync::Lazy;
4
5use super::type_ref::TypeRefExt;
6use super::RustNativeGeneratedElement;
7use crate::type_ref::Constness;
8use crate::writer::rust_native::class::ClassExt;
9use crate::writer::rust_native::element::RustElement;
10use crate::{AbstractRefWrapper, CompiledInterpolation, NameStyle, StrExt};
11
12impl RustNativeGeneratedElement for AbstractRefWrapper<'_, '_> {
13 fn element_order(&self) -> u8 {
14 10
15 }
16
17 fn element_safe_id(&self) -> String {
18 let type_ref = self.type_ref();
19 format!("{}-{}", type_ref.rust_module().opencv_name(), type_ref.rust_safe_id(true))
20 }
21
22 fn gen_rust(&self, _opencv_version: &str) -> String {
23 static RUST: Lazy<CompiledInterpolation> =
24 Lazy::new(|| include_str!("tpl/abstract_ref_wrapper/rust.tpl.rs").compile_interpolation());
25
26 let type_ref = self.type_ref().source();
27 let type_ref_kind = type_ref.kind();
28 let cls = type_ref_kind.as_class().expect("Can only make an abstract ref to a class");
29 RUST.interpolate(&HashMap::from([
30 ("rust_full", cls.rust_name(NameStyle::ref_())),
31 ("rust_trait_const", cls.rust_trait_name(NameStyle::ref_(), Constness::Const)),
32 ("rust_trait_mut", cls.rust_trait_name(NameStyle::ref_(), Constness::Mut)),
33 ("rust_as_raw_const", cls.rust_as_raw_name(Constness::Const).into()),
34 ("rust_as_raw_mut", cls.rust_as_raw_name(Constness::Mut).into()),
35 ]))
36 }
37}