Skip to content

Ingorable Rust snippets #423

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

Closed
dragostis opened this issue Sep 3, 2017 · 7 comments
Closed

Ingorable Rust snippets #423

dragostis opened this issue Sep 3, 2017 · 7 comments

Comments

@dragostis
Copy link

Is there a way to add ignorable Rust snippets like in rustdoc?

@azerupi
Copy link
Contributor

azerupi commented Sep 3, 2017

There is a PR open #404 to add a no_run attribute on code blocks. Does that cover your use case?

@dragostis
Copy link
Author

no_run probably tries to compile the code, so it probably won't work. I would only need a code snippet that highlights Rust code.

@budziq
Copy link
Contributor

budziq commented Sep 3, 2017

Hi @dragostis

The code snippets are not compiled unless you:

  1. use the play button - then it is compiled remotely by the https://play.rust-lang.org/
  2. call mdbook test - then it is compiled by rustdoc
  3. use some third party test runner like rust-skeptic which integrates with cargo test

In all cases all you need is one of two annotations for code blocks:

  • no_run - code gets compiled but tests are not run
  • ignore - code does not get compiled at all

in case 1. you'll need PR #404 to be merged for the play button to respect no_run and ignore but mdbook test and rust-skeptic already understand these annotations. So I guess that your use case is already covered.

@dragostis
Copy link
Author

Oh, I see. That makes complete sense. However, is there a way to add crate dependencies?

@budziq
Copy link
Contributor

budziq commented Sep 3, 2017

It depends on which of the three cases are you thinking.

  1. play button - nothing. You'll get only the crates that are installed on https://play.rust-lang.org/. PR Dynamic play button based on no_run property and used crates availability  #404 disables play button if the used crates are not available there.
  2. mdbook test - you'll have to use -L /path/to/compiled/deps introduced since https://github.com/azerupi/mdBook/pull/340/ which requires that your project somehow depends on the extern crates (ie. these are listed in Cargo.toml like in case of 3.)
  3. third party runners - well its depends on which one you use. For instance rust-skeptic requires that you add dependent crates to the Cargo.toml

I hope that solves your problem.

@dragostis
Copy link
Author

Thank you for the detailed answer. That makes sense. I guess this should probably be covered in book.

@budziq
Copy link
Contributor

budziq commented Sep 3, 2017

That makes sense. I guess this should probably be covered in book.

@dragostis Indeed it should! We are planning to release a new version (which is mostly blocked on minor regressions to be fixed and documentation update). Unfortunately the progress with docs update is slow as we do not have as much time on our hands as we would like ;) If you are willing to contribute some time to provide a PR that would update the docs somewhat It would be more than welcome :)

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