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

Thoughts on updating documentation/examples #1156

Closed
jkaye2012 opened this issue Oct 12, 2019 · 3 comments
Closed

Thoughts on updating documentation/examples #1156

jkaye2012 opened this issue Oct 12, 2019 · 3 comments
Labels
accepted An accepted request or suggestion docs Improvements or additions to documentation suggestion A suggestion to change functionality

Comments

@jkaye2012
Copy link

Thanks for the fantastic library!

I have been reading through documentation and examples to learn about Rocket. One thing that confused me is the use of macro_use, extern crate, and serde_derive, none of which I believe are necessary any more (or at least they do not appear to be in my testing). For example, the tera_template example currently begins with:

#[macro_use] extern crate rocket;
#[macro_use] extern crate serde_derive;

But I am able to serve templates through routes with:

use rocket::{get, routes};
use rocket_contrib::templates::Template;
use serde::Serialize;

Of course, I have the serde "derive" feature enabled.

I also noticed another line in the doc that seems to perhaps not be currently, namely that #![feature(proc_macro_hygiene, decl_macro)] must be in the crate entrypoint; I have it instead in a library module and things are working well.

I would be happy to submit a pull request containing this kind of update, but wanted to get some feedback on all of this first. Maybe there's some reason that I'm unaware of that the currently documented way is preferred? I'm relatively new to Rust, so it's hard for me to know.

Thanks!

@jebrosen jebrosen added accepted An accepted request or suggestion docs Improvements or additions to documentation suggestion A suggestion to change functionality labels Oct 12, 2019
@jebrosen
Copy link
Collaborator

Thanks for bringing this up! The examples were all written before Rust 2018, and some things were not fully updated.

  • IIRC leaving #[macro_use] extern crate rocket; was a deliberate style choice: this form allows you to use #[get], #[post], and so on in any module without importing the attributes individually. That conversation is probably somewhere in Rust 2018 #1013.
  • serde_derive should definitely be switched; I believe what you described is indeed the recommended form to use today.

#![feature(proc_macro_hygiene, decl_macro)] must be in the crate entrypoint; I have it instead in a library module and things are working well.

If by "a library module" you are referring to lib.rs, then that is indeed the crate entrypoint (of the library crate). If you mean any other module, you should be seeing a warning: crate-level attribute should be in the root module and errors where those features are actually used.

I would be happy to submit a pull request containing this kind of update, but wanted to get some feedback on all of this first.

We are happy to see pull requests, and docs/examples updates are usually pretty quick and easy for us to review and merge.

@jkaye2012
Copy link
Author

Great, that makes sense. I'll try to put something together when I have time. Thanks again!

@songroom2016
Copy link

songroom2016 commented Nov 7, 2019

can add an example of compression( such as gzip....)?
i think that compression is important .

jebrosen added a commit to jebrosen/Rocket that referenced this issue Jul 19, 2020
jebrosen added a commit to jebrosen/Rocket that referenced this issue Jul 19, 2020
jebrosen added a commit to jebrosen/Rocket that referenced this issue Jul 19, 2020
jebrosen added a commit to jebrosen/Rocket that referenced this issue Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted An accepted request or suggestion docs Improvements or additions to documentation suggestion A suggestion to change functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants