Diggsey / rnet

Apache License 2.0
79 stars 5 forks source link

Does rnet work with generics #7

Open mercurial-moon opened 3 weeks ago

mercurial-moon commented 3 weeks ago

Hi I'm trying to use rnet for this library https://github.com/lukaslueg/railroad which makes heavy use of generics when I add the Net tag to a struct like so

#[derive(Debug, Clone, Net)]
pub struct Link<N> {
    inner: N,
    uri: String,
    target: Option<LinkTarget>,
    attributes: HashMap<String, String>,
}

it gives error like

error[E0412]: cannot find type N in this scope --> src\lib.rs:290:12 | 290 | inner: N, | ^ not found in this scope

do I need to configure rnet for use with generics?

Diggsey commented 3 weeks ago

You cannot expose generics through rnet (or indeed any Rust <=> non-Rust interop mechanism) since Rust generics must be instantiated with known types are compile time, whereas in .net, generics are instantiated at runtime.

mercurial-moon commented 3 weeks ago

Is there any workaround or alternative way where I can get this done, I researched around and people suggested using macros to create wrapper functions. Like here https://stackoverflow.com/questions/77742660/how-can-i-export-a-generic-rust-function-to-a-c-header