pub use crate::ir::analysis::DeriveTrait;
pub use crate::ir::derive::CanDerive as ImplementsTrait;
pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue};
pub use crate::ir::int::IntKind;
use std::fmt;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum MacroParsingBehavior {
Ignore,
#[default]
Default,
}
pub trait ParseCallbacks: fmt::Debug {
#[cfg(feature = "__cli")]
#[doc(hidden)]
fn cli_args(&self) -> Vec<String> {
vec![]
}
fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior {
MacroParsingBehavior::Default
}
fn generated_name_override(
&self,
_item_info: ItemInfo<'_>,
) -> Option<String> {
None
}
fn generated_link_name_override(
&self,
_item_info: ItemInfo<'_>,
) -> Option<String> {
None
}
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind> {
None
}
fn str_macro(&self, _name: &str, _value: &[u8]) {}
fn func_macro(&self, _name: &str, _value: &[&[u8]]) {}
fn enum_variant_behavior(
&self,
_enum_name: Option<&str>,
_original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<EnumVariantCustomBehavior> {
None
}
fn enum_variant_name(
&self,
_enum_name: Option<&str>,
_original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<String> {
None
}
fn item_name(&self, _original_item_name: &str) -> Option<String> {
None
}
fn header_file(&self, _filename: &str) {}
fn include_file(&self, _filename: &str) {}
fn read_env_var(&self, _key: &str) {}
fn blocklisted_type_implements_trait(
&self,
_name: &str,
_derive_trait: DeriveTrait,
) -> Option<ImplementsTrait> {
None
}
fn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec<String> {
vec![]
}
fn add_attributes(&self, _info: &AttributeInfo<'_>) -> Vec<String> {
vec![]
}
fn process_comment(&self, _comment: &str) -> Option<String> {
None
}
fn field_visibility(
&self,
_info: FieldInfo<'_>,
) -> Option<crate::FieldVisibilityKind> {
None
}
#[cfg(feature = "experimental")]
fn wrap_as_variadic_fn(&self, _name: &str) -> Option<String> {
None
}
fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem) {}
}
#[derive(Ord, PartialOrd, PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct DiscoveredItemId(usize);
impl DiscoveredItemId {
pub fn new(value: usize) -> Self {
Self(value)
}
}
#[derive(Debug, Hash, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum DiscoveredItem {
Struct {
original_name: Option<String>,
final_name: String,
},
Union {
original_name: Option<String>,
final_name: String,
},
Alias {
alias_name: String,
alias_for: DiscoveredItemId,
}, }
#[derive(Debug)]
#[non_exhaustive]
pub struct DeriveInfo<'a> {
pub name: &'a str,
pub kind: TypeKind,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct AttributeInfo<'a> {
pub name: &'a str,
pub kind: TypeKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TypeKind {
Struct,
Enum,
Union,
}
#[non_exhaustive]
pub struct ItemInfo<'a> {
pub name: &'a str,
pub kind: ItemKind,
}
#[non_exhaustive]
pub enum ItemKind {
Function,
Var,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct FieldInfo<'a> {
pub type_name: &'a str,
pub field_name: &'a str,
pub field_type_name: Option<&'a str>,
}