mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-22 22:46:26 +00:00
Adds a setting to force some types to always be included in the emitted types.
This is useful to support, for example, enum types whose values are significant but whose type is not explicitly used in the functions prototypes.
This commit is contained in:
parent
2c57dced0f
commit
1e7d81d618
@ -32,6 +32,7 @@ pub struct BindgenOptions {
|
|||||||
pub csharp_use_nint_types: bool,
|
pub csharp_use_nint_types: bool,
|
||||||
pub csharp_imported_namespaces: Vec<String>,
|
pub csharp_imported_namespaces: Vec<String>,
|
||||||
pub csharp_generate_const_filter: fn(const_name: &str) -> bool,
|
pub csharp_generate_const_filter: fn(const_name: &str) -> bool,
|
||||||
|
pub always_included_types: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Builder {
|
impl Default for Builder {
|
||||||
@ -57,6 +58,7 @@ impl Default for Builder {
|
|||||||
csharp_use_nint_types: true,
|
csharp_use_nint_types: true,
|
||||||
csharp_imported_namespaces: vec![],
|
csharp_imported_namespaces: vec![],
|
||||||
csharp_generate_const_filter: |_| false,
|
csharp_generate_const_filter: |_| false,
|
||||||
|
always_included_types: vec![],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +89,14 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds a list of types that will always be considered to be included in the
|
||||||
|
/// generated bindings, even if not part of any function signature
|
||||||
|
pub fn always_included_types<I, S>(mut self, always_included_types: I) -> Builder
|
||||||
|
where I: IntoIterator<Item = S>, S: ToString
|
||||||
|
{
|
||||||
|
self.options.always_included_types.extend(always_included_types.into_iter().map(|v| v.to_string()));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// add original extern call type prefix to rust wrapper,
|
/// add original extern call type prefix to rust wrapper,
|
||||||
/// `return {rust_method_type_path}::foo()`
|
/// `return {rust_method_type_path}::foo()`
|
||||||
|
@ -78,6 +78,8 @@ pub(crate) fn generate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using_types.extend(options.always_included_types.iter().cloned());
|
||||||
|
|
||||||
let structs = reduce_struct(&structs, &field_map, &using_types);
|
let structs = reduce_struct(&structs, &field_map, &using_types);
|
||||||
let enums = reduce_enum(&enums, &field_map, &using_types);
|
let enums = reduce_enum(&enums, &field_map, &using_types);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user