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

allow converting an expr to its Display impl #26

Open
kianenigma opened this issue Jun 3, 2024 · 3 comments
Open

allow converting an expr to its Display impl #26

kianenigma opened this issue Jun 3, 2024 · 3 comments

Comments

@kianenigma
Copy link

The scenario is this.

In your test functions, you have:

#[test]
fn test_ls() {
  let process = Command::new(ls).arg("ln");
  // we then test that ls works as expected
}

and we want to show the same example in our docs, but showing let process = Command::new(ls).arg("ln") is not great. Ideally, we want to use Debug/Display impl of the same process variable, which will nicely format it as ls -ln.

I suppose this can be done with

#[test]
fn test_ls() {
  #[docify::export_display]
  let process = Command::new(ls).arg("ln");
  // we then test that ls works as expected
}

This is a very limited use-case. We can easily limit it to only work in assignment expressions, drop the lhs, assert rhs is a Command etc.

@sam0x17
Copy link
Owner

sam0x17 commented Jun 3, 2024

so how would it look in the rendered docs?

@kianenigma
Copy link
Author

the example I have should render as ln -ls

@sam0x17
Copy link
Owner

sam0x17 commented Jun 4, 2024

for this to work the expr it is attached to would have to compile and run within the docify proc macro so it can expand to a string there -- remember we are ultimately in doc comment position, so you have to think of these as compile-time Display impls. Probably what this should be is an attribute attached to a function where the function returns a String, and that function would be expected to compile without issues when copy-pasted into an arbitrary proc macro, in other words it can't use dependencies.

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