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

Use absolute paths in derive macro #124

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

novafacing
Copy link
Contributor

@novafacing novafacing commented Dec 8, 2024

Uses absolute paths in derive-macro generated code to permit not using top-level use statements.

This permits things like:

#[derive(nanoserde::SerJson, nanoserde::DeJson)]
pub struct Foo {
  val: String,
}

Without having a use nanoserde::{SerJson, DeJson} at global scope.

This would solve #45 for my use case.

@knickish
Copy link
Collaborator

knickish commented Dec 9, 2024

Thanks for working on this. I'm concerned that hard coding these paths will prevent the derive macros from being used if the crate is renamed in Cargo.toml, which is a use case that has been supported so far. I would lean towards accepting this if an override similar to #[serde(crate = "renamed_serde")] was also present, as there's still time to add that before v0.2. Any opinions on that @not-fl3?

@novafacing
Copy link
Contributor Author

novafacing commented Dec 11, 2024

I went ahead and added the ability to rename the crate like so (better example in the added tests).

use nanoserde as other;
#[derive(other::DeJson)]
#[nserde(crate = "other")]
struct Foo;

@knickish
Copy link
Collaborator

I'd like to wait and see if @not-fl3 has any opinion on it before merging, but that looks great to me, appreciate it.

@not-fl3
Copy link
Owner

not-fl3 commented Dec 11, 2024

Looks great to me too!

@knickish knickish merged commit a7113a2 into not-fl3:master Dec 11, 2024
16 checks passed
@novafacing novafacing deleted the absolute-paths branch December 11, 2024 17:27
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

Successfully merging this pull request may close these issues.

3 participants