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

[Feature request] Push some validation to compiletime #20

Open
richard-uk1 opened this issue Nov 29, 2018 · 3 comments
Open

[Feature request] Push some validation to compiletime #20

richard-uk1 opened this issue Nov 29, 2018 · 3 comments

Comments

@richard-uk1
Copy link
Contributor

The following snippet will fail at runtime:

html!(
  <link href="sub/path.css" rel="stylesheet"/>
)

The reason for this is that "sub/path.css" is not a valid URI. If you do the following

html!(
  <link href={"sub/path.css"} rel="stylesheet"/>
)

you will get a failure at compile-time, because here the contents of href must be a Uri (the first version using str.parse::<Uri>().unwrap()).

It would be good if the proc macro tries this Uri conversion at compile-time, and rejects the program if the string isn't a valid Uri.


Unrelated, but TIL that './relative/path' is not a valid URI, at least according to hyper/http.

@bodil
Copy link
Owner

bodil commented Nov 29, 2018

Problem is it's really hard to do, because the macro doesn't even know that the attribute takes a Uri, it just generates the code for the type checker to validate later (the only checking it does is whether it's a string literal so it'll generate .parse() instead of .into()). I feel like there must be some way to do it, but I haven't found it yet.

@richard-uk1
Copy link
Contributor Author

richard-uk1 commented Nov 29, 2018

Aah ok I see, the parser would need more context information.

EDIT

The big caveat for this: currently, the macro is not able to validate the string at compile time, and the conversion will panic at runtime if the string is invalid.

Apologies I should have seen this.

@bodil
Copy link
Owner

bodil commented Nov 30, 2018

No worries, it's good to have an explicit issue for it, because I really want to find a good solution for it even if it turns out there isn't one.

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