Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exporting generic type with do_export!() #182

Closed
is-it-ayush opened this issue Dec 11, 2023 · 6 comments
Closed

exporting generic type with do_export!() #182

is-it-ayush opened this issue Dec 11, 2023 · 6 comments

Comments

@is-it-ayush
Copy link

Hi! I manually export my structs so that I can create an index.ts barrel file and re-export generated types for those structs within my rust package. I achieve this with do_export!() macro where I first export every struct and then at last create my barrel file.

This method works perfectly fine for normal structs. The problem occurs with generic structs that expect a type argument to be passed to them. Here's an example,

struct StructA {
  prop: String,
}

do_export!(StructA); // good & works great.

struct StructB<T> {
  prop: T,
}

do_export!(StructB); // eh! doesn't work anymore since it expects an arguements

I know ts-rs supports exporting generic structs but are there any solutions for exporting generic structs with do_export!() macro?

@escritorio-gustavo
Copy link
Contributor

I don't think this macro is in the crate anymore

@NyxCode
Copy link
Collaborator

NyxCode commented Feb 2, 2024

Confused about this as well. I don't think we ever had a macro do_export!, so I think this is something @is-it-ayush implemented?

@escritorio-gustavo
Copy link
Contributor

escritorio-gustavo commented Feb 2, 2024

Maybe he means the old export!?

But I've read some other issues and that doesn't seem like it's the correct syntax for it either. From what I could gather it used to be

export!(Type => "path")

@escritorio-gustavo
Copy link
Contributor

Either way, seems like @is-it-ayush is trying to do the same as #133

@is-it-ayush
Copy link
Author

I apologise!! this is my oopsie. The macro simply called the ::export() on the type. Here's the macro definition, I forget that I had found this macro from somewhere else and started associating this with a macro provided by ts-rs crate.

macro_rules! do_export {
    ($a:ty) => {{
        match <$a>::export() {
            Ok(()) => {
                println!("✅ {}", <$a>::name());
            }
            Err(e) => {
                println!("❌ {} failed: {}", <$a>::name(), e);
            }
        }
    }};
}

In terms of this issue. I ended up writing a bash script that looped over the directory files ending with .ts and created a new index.ts with all the exports within it. Here's the shell script code.

@escritorio-gustavo
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants