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

Document RustcEncodable/RustcDecodable #298

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/rust-2024/prelude.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ More information may be found in the tracking issue at <https://github.com/rust-

- The [`Future`] and [`IntoFuture`] traits are now part of the prelude.
- This might make calls to trait methods ambiguous which could make some code fail to compile.
- `RustcEncodable` and `RustcDecodable` have been removed from the prelude.

[`Future`]: ../../std/future/trait.Future.html
[`IntoFuture`]: ../../std/future/trait.IntoFuture.html
Expand All @@ -26,10 +27,24 @@ However, adding a _trait_ to the prelude can break existing code in a subtle way
For example, a call to `x.poll()` which comes from a `MyPoller` trait might fail to compile if `std`'s `Future` is also imported, because the call to `poll` is now ambiguous and could come from either trait.

As a solution, Rust 2024 will use a new prelude.
It's identical to the current one, except for two new additions:
It's identical to the current one, except for the following changes:

- [`std::future::Future`][`Future`]
- [`std::future::IntoFuture`][`IntoFuture`]
- Added:
- [`std::future::Future`][`Future`]
- [`std::future::IntoFuture`][`IntoFuture`]
- Removed:
- `RustcEncodable`
- `RustcDecodable`

### `RustcEncodable` and `RustcDecodable` removal

`RustcEncodable` and `RustcDecodable` are two undocumented derive macros that have been removed from the prelude.
These were deprecated before Rust 1.0, but remained within the standard library prelude.
The 2024 Edition has removed these from the prelude since they are not expected to be used.

If in the unlikely case there is a project still using these, it is recommended to switch to a serialization library, such as those found on [crates.io].

[crates.io]: https://crates.io/categories/encoding

## Migration

Expand Down Expand Up @@ -67,3 +82,13 @@ fn main() {
<_ as MyPoller>::poll(&core::pin::pin!(async {}));
}
```

#### `RustcEncodable` and `RustcDecodable`

It is strongly recommended that you migrate to a different serialization library if you are still using these.
However, these derive macros are still available in the standard library, they are just required to be imported from the older prelude now:

```rust,edition2021
#[allow(soft_unstable)]
use core::prelude::v1::{RustcDecodable, RustcEncodable};
```