Sebekerga / native_api_1c

Crate for simple implementation of Component for Native API 1C:Enterprise written in rust
https://crates.io/crates/native_api_1c
61 stars 13 forks source link

Is it possible to take custom data types as args? #20

Closed blackdllx closed 3 months ago

Sebekerga commented 3 months ago

Yes, as long your types implement From traits for given parameter type. In other words, this should work:

struct CustomType {
  inner_string: String
}

impl From<String> for CustomType {
...
}

#[derive(AddIn)]
struct MyAddIn {
...
    #[add_in_func(name = "MyProcedure", name_ru = "МояПроцедура")]
    #[arg(ty = Str)]
    pub my_procedure: fn(CustomType)
...
}

This works, because I am using .into() when converting from 1C types to rust, same the other way: https://github.com/Sebekerga/native_api_1c/blob/6e8dcccb305dab3869c51ed9e0d7a30be714f068/native_api_1c_macro/src/derive_addin/common_generators.rs#L18-L25

I'm not 100% sure if it will work with out params, this is something that is not stable, ...yet

blackdllx commented 3 months ago

I meant take custom data type from 1c. What about enumerations? Can i import it from 1c to rust?

Sebekerga commented 3 months ago

Unfortunately, no, you are limited by primitive types: https://its.1c.ru/db/metod8dev#content:3221:hdoc:_tvariant_enterprise