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

Support for borrowing newtypes #133

Open
Ducky2048 opened this issue Apr 15, 2024 · 1 comment
Open

Support for borrowing newtypes #133

Ducky2048 opened this issue Apr 15, 2024 · 1 comment

Comments

@Ducky2048
Copy link

First of all, thank you for this library! I like it a lot.

I have a request:

I would like to make newtypes containing borrowed values, but it appears that doesn't work.

For example, this:

#[nutype(derive(Debug))]
struct A<'a>(Cow<'a, str>);

Expands to this:

#[doc(hidden)]
mod __nutype_private_A__ {
    use super::*;

    #[derive(Debug, )]
   /// Lifetime on A is missing
    pub struct A(Cow<'a, str>);

    impl A {
        pub fn new(raw_value: Cow<'a, str>) -> Self {
            fn sanitize(mut value: Cow<'a, str>) -> Cow<'a, str> { value }
            Self(sanitize(raw_value))
        }
    }

    impl A { pub fn into_inner(self) -> Cow<'a, str> { self.0 } }
}
use __nutype_private_A__::A

The important part is that the lifetime declaration on A seems to be lost. Is it possible to make this work?

@Ducky2048 Ducky2048 changed the title Support for Cow Support for borrowing newtypes Apr 15, 2024
@greyblake
Copy link
Owner

Hi, thanks for reporting the issue.
Currently generics are not yet support, but I plan to add support for this.
There is a related issue to this: #130

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

2 participants