-
Notifications
You must be signed in to change notification settings - Fork 507
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
chore: improve no_std
maintainability:
#1047
base: master
Are you sure you want to change the base?
Conversation
c6b53e6
to
4023a9c
Compare
Similar to how `rustls` does it: https://github.com/rustls/rustls/blob/513e374b2e2ce9f1fb57ac78ab3ca053afc8f133/rustls/src/lib.rs#L353-L359 > ... `extern crate` plus the `#![no_std]` attribute changes the default prelude from `std::prelude` to `core::prelude`. That forces one to _explicitly_ import (`use`) everything that is in `std::prelude` but not in `core::prelude`. This helps maintain no-std support as even developers that are not interested in, or aware of, no-std support and / or that never run `cargo build --no-default-features` locally will get errors when they rely on `std::prelude` API.
Makes it easier to fix tokio-rs#939 because there were places where the prost_path setting was being ignored when direct a direct alloc path would suffice: https://github.com/tokio-rs/prost/blob/691454307ccd2de4c780438da8acf2a1ddd994f6/prost-build/src/code_generator.rs#L648
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of better no_std
maintainability, but this PR introduces multiple concepts. I think it would be better reviewable if those are split into multiple PRs.
pub enum Data { | ||
#[prost(message, tag="1")] | ||
Foo(::prost::alloc::boxed::Box<super::Foo>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the generated code should always use a fully qualified type path, as they could otherwise clash with a user-generated type.
@@ -0,0 +1,90 @@ | |||
//! A facade around all the types we need from the `std`, `core`, and `alloc` | |||
//! crates. This avoids elaborate import wrangling having to happen in every | |||
//! module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the facade concept. If we keep it, it should work like the ::std::prelude
. But I think it is better to be explicit about your dependencies.
#![doc = include_str!("../../README.md")] | ||
#![no_std] | ||
|
||
// See: https://github.com/tokio-rs/prost/pull/1047 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code should not refer to Github issues, but instead contain the contents directly
Similar to how
rustls
does it:https://github.com/rustls/rustls/blob/513e374b2e2ce9f1fb57ac78ab3ca053afc8f133/rustls/src/lib.rs#L353-L359