pub struct ExternModuleTranslator {
    pub shared_enums: HashSet<ItemEnum>,
    pub exception_names: HashSet<String>,
    pub rust_types_wrappers: OrderedHashSet<WrapperType>,
    pub user_custom_types: HashMap<WrapperType, Vec<Function>>,
    pub user_traits: HashMap<WrapperType, Vec<Function>>,
    pub global_functions: Vec<Function>,
    pub exception_trait_methods: HashSet<Function>,
}
Expand description

The structure keeps the Rust types wrappers, methods of the structures and global functions signatures. user_custom_types is a subset of rust_types_wrappers, since the latter collection keeps all the wrappers that will be handled, and the first one keeps only a user defined types wrappers along with their methods.

Fields§

§shared_enums: HashSet<ItemEnum>§exception_names: HashSet<String>§rust_types_wrappers: OrderedHashSet<WrapperType>§user_custom_types: HashMap<WrapperType, Vec<Function>>§user_traits: HashMap<WrapperType, Vec<Function>>§global_functions: Vec<Function>§exception_trait_methods: HashSet<Function>

Implementations§

Takes extern “Rust” module and translates its functions. It also stores information about the functions signatures for a further processing.

Takes extern “Traits” module and translates its functions. It also stores information about the functions signatures for a further processing.

Takes extern “ExceptionTrait” module and translates its methods. It also stores information about the functions signatures for a further processing.

Example: fn foo(self: &SomeType) -> Result<AnotherType> ==> fn foo(self: &SomeType) -> ResultAnotherType.

The method takes the Rust function signature and registers every type as a WrapperType as well as translates it into inner function form Function. If the type has a self argument it returns its WrapperType in the result.

Example:

use syn::{ForeignItemFn, parse_quote};
use rusty_bind_parser::extern_module_translator::*;


let mut local_module_translator = ExternModuleTranslator::default();
let function: ForeignItemFn = parse_quote! { fn foo(self: &SomeType, a: u32) -> Option<u32>; };
if let (Some(associated_type), Function {
    arguments,
    return_type: Some(return_type),
    name,
}) = local_module_translator.translate_function(function).unwrap() {
    assert!(name == "foo");
    assert!(arguments.len() == 2);
    assert!(arguments[0] == Arg {arg_name: "self".to_owned(), typ: WrapperType {
        original_type_name: parse_quote! { SomeType },
        wrapper_name: "SomeType".to_owned(),
        rust_type: RustWrapperType::Custom,
        is_ref: true,
        is_mut: false,
    }});
    assert!(arguments[1] == Arg {arg_name: "a".to_owned(), typ: WrapperType {
        original_type_name: parse_quote! { u32 },
        wrapper_name: "u32".to_owned(),
        rust_type: RustWrapperType::Primitive,
        is_ref: false,
        is_mut: false,
    }});
    assert!(associated_type == WrapperType {
        original_type_name: parse_quote! { SomeType },
        wrapper_name: "SomeType".to_owned(),
        rust_type: RustWrapperType::Custom  ,
        is_ref: true,
        is_mut: false,
    });
    println!("{return_type:?}");
    assert!(return_type == WrapperType {
        original_type_name: parse_quote! { Option<u32> },
        wrapper_name: "Optionalu32".to_owned(),
        rust_type: RustWrapperType::Option(
            WrapperType {
                original_type_name: parse_quote! { u32 },
                wrapper_name: "u32".to_owned(),
                rust_type: RustWrapperType::Primitive,
                is_ref: false,
                is_mut: false,
            }.boxed()
        ),
        is_ref: false,
        is_mut: false,
    });
} else {
    panic!("Translated function doesn't match.");
}

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.