oo_bindgen/backend/c/cpp/conversion/
to_cpp_return_value.rs

1use crate::backend::c::cpp::conversion::ToCpp;
2use crate::model::FunctionReturnValue;
3
4pub(crate) trait ToCppReturnValue {
5    fn to_cpp_return_value(&self, expr: String) -> String;
6    fn transform_in_wrapper(&self) -> bool;
7}
8
9impl ToCppReturnValue for FunctionReturnValue {
10    fn to_cpp_return_value(&self, expr: String) -> String {
11        match self {
12            FunctionReturnValue::Basic(x) => x.to_cpp(expr),
13            FunctionReturnValue::String(x) => x.to_cpp(expr),
14            FunctionReturnValue::ClassRef(_) => {
15                format!("::convert::to_cpp({expr})")
16            }
17            FunctionReturnValue::Struct(_) => {
18                format!("::convert::to_cpp({expr})")
19            }
20            FunctionReturnValue::StructRef(_) => {
21                //  we don't transform struct refs in the wrappers
22                expr
23            }
24            FunctionReturnValue::PrimitiveRef(_) => {
25                // point to a primitive same in C++
26                expr
27            }
28        }
29    }
30
31    fn transform_in_wrapper(&self) -> bool {
32        match self {
33            FunctionReturnValue::Basic(_) => true,
34            FunctionReturnValue::String(_) => true,
35            FunctionReturnValue::ClassRef(_) => false,
36            FunctionReturnValue::Struct(_) => true,
37            FunctionReturnValue::StructRef(_) => false,
38            FunctionReturnValue::PrimitiveRef(_) => false,
39        }
40    }
41}