pub trait ParseCallbacks: Send + Sync {
fn item_name(&self, _info: &ItemInfo) -> Option<String> {
None
}
fn field_name(&self, _info: &FieldInfo) -> Option<String> {
None
}
fn module_name(&self, _info: &ItemInfo) -> Option<String> {
None
}
fn add_derives(&self, _info: &ItemInfo) -> Vec<String> {
Vec::new()
}
fn add_attributes(&self, _info: &ItemInfo) -> Vec<String> {
Vec::new()
}
fn add_field_attributes(&self, _field_info: &FieldInfo) -> Vec<String> {
Vec::new()
}
fn custom_impl(&self, _info: &ItemInfo) -> Option<String> {
None
}
fn custom_impl_tokens(&self, _info: &ItemInfo) -> Option<proc_macro2::TokenStream> {
None
}
fn include_item(&self, _info: &ItemInfo) -> bool {
true
}
fn sequence_type(
&self,
_element_type: &str,
_max_size: Option<u32>,
_ros2_type: &str,
) -> Option<String> {
None
}
fn string_type(&self, _max_size: Option<u32>) -> Option<String> {
None
}
fn wstring_type(&self, _max_size: Option<u32>) -> Option<String> {
None
}
fn pre_module(&self, _info: &ModuleInfo) -> Option<String> {
None
}
fn post_module(&self, _info: &ModuleInfo) -> Option<String> {
None
}
fn pre_module_tokens(&self, _info: &ModuleInfo) -> Option<proc_macro2::TokenStream> {
None
}
fn post_module_tokens(&self, _info: &ModuleInfo) -> Option<proc_macro2::TokenStream> {
None
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ModuleLevel {
Package,
InterfaceKind(super::InterfaceKind),
Type(super::InterfaceKind),
}
#[derive(Debug, Clone)]
pub struct ModuleInfo {
module_name: String,
parent_path: String,
package: String,
module_level: ModuleLevel,
}
impl ModuleInfo {
#[must_use]
pub(crate) fn new(
module_name: String,
parent_path: String,
package: String,
module_level: ModuleLevel,
) -> Self {
Self {
module_name,
parent_path,
package,
module_level,
}
}
#[must_use]
pub fn module_name(&self) -> &str {
&self.module_name
}
#[must_use]
pub fn parent_path(&self) -> &str {
&self.parent_path
}
#[must_use]
pub fn package(&self) -> &str {
&self.package
}
#[must_use]
pub fn module_level(&self) -> ModuleLevel {
self.module_level
}
#[must_use]
pub fn full_path(&self) -> String {
if self.parent_path.is_empty() {
self.module_name.clone()
} else {
format!("{}::{}", self.parent_path, self.module_name)
}
}
}
#[derive(Debug, Clone)]
pub struct ItemInfo {
name: String,
source_file: String,
package: String,
interface_kind: super::InterfaceKind,
}
impl ItemInfo {
#[must_use]
pub(super) fn new(
name: String,
source_file: String,
package: String,
interface_kind: super::InterfaceKind,
) -> Self {
Self {
name,
source_file,
package,
interface_kind,
}
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn source_file(&self) -> &str {
&self.source_file
}
#[must_use]
pub fn package(&self) -> &str {
&self.package
}
#[must_use]
pub fn interface_kind(&self) -> super::InterfaceKind {
self.interface_kind
}
}
#[derive(Debug, Clone)]
pub struct FieldInfo {
field_name: String,
field_type: String,
parent_name: String,
package: String,
ros_type_name: String,
array_size: Option<u32>,
ros2_type_override: Option<String>,
capacity: Option<u32>,
string_capacity: Option<u32>,
default_value: Option<String>,
}
impl FieldInfo {
#[must_use]
#[allow(clippy::too_many_arguments)]
pub(super) fn new(
field_name: String,
field_type: String,
parent_name: String,
package: String,
ros_type_name: String,
array_size: Option<u32>,
ros2_type_override: Option<String>,
capacity: Option<u32>,
string_capacity: Option<u32>,
default_value: Option<String>,
) -> Self {
Self {
field_name,
field_type,
parent_name,
package,
ros_type_name,
array_size,
ros2_type_override,
capacity,
string_capacity,
default_value,
}
}
#[must_use]
pub fn field_name(&self) -> &str {
&self.field_name
}
#[must_use]
pub fn field_type(&self) -> &str {
&self.field_type
}
#[must_use]
pub fn parent_name(&self) -> &str {
&self.parent_name
}
#[must_use]
pub fn package(&self) -> &str {
&self.package
}
#[must_use]
pub fn ros_type_name(&self) -> &str {
&self.ros_type_name
}
#[must_use]
pub fn array_size(&self) -> Option<u32> {
self.array_size
}
#[must_use]
pub fn ros2_type_override(&self) -> Option<&str> {
self.ros2_type_override.as_deref()
}
#[must_use]
pub fn capacity(&self) -> Option<u32> {
self.capacity
}
#[must_use]
pub fn string_capacity(&self) -> Option<u32> {
self.string_capacity
}
#[must_use]
pub fn default_value(&self) -> Option<&str> {
self.default_value.as_deref()
}
}