09980e01f5
Suggest less bug-prone construction of Duration in docs std::time::Duration has a well-known quirk: Duration::as_nanos() returns u128 [1], but Duration::from_nanos() takes u64 [2]. So these methods cannot easily roundtrip [3]. It is not possible to simply accept u128 in from_nanos [4], because it requires breaking other API [5]. It seems to me that callers have basically only two options: 1. `Duration::from_nanos(d.as_nanos() as u64)`, which is the "obvious" and buggy approach. 2. `Duration::new(d.as_secs(), d.subsecs_nanos())`, which only becomes apparent after reading and digesting the entire Duration struct documentation. I suggest that the documentation of `from_nanos` is changed to make option 2 more easily discoverable. There are two major usecases for this: - "Weird math" operations that should not be supported directly by `Duration`, like squaring. - "Disconnected roundtrips", where the u128 value is passed through various other stack frames, and perhaps reconstructed into a Duration on a different machine. In both cases, it seems like a good idea to not tempt people into thinking "Eh, u64 is good enough, what could possibly go wrong!". That's why I want to add a note that points out the similarly-easy and *safe* way to reconstruct a Duration. [1] https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.as_nanos [2] https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.from_nanos [3] https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fa6bab2b6b72f20c14b5243610ea1dde [4] https://github.com/rust-lang/rust/issues/103332 [5] https://github.com/rust-lang/rust/issues/51107#issuecomment-392353166 |
||
---|---|---|
.cargo | ||
.github | ||
.vscode | ||
assets | ||
bench_data | ||
crates | ||
docs | ||
editors/code | ||
lib | ||
xtask | ||
.editorconfig | ||
.git-blame-ignore-revs | ||
.gitattributes | ||
.gitignore | ||
.typos.toml | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
PRIVACY.md | ||
README.md | ||
rust-bors.toml | ||
rustfmt.toml | ||
triagebot.toml |
rust-analyzer is a modular compiler frontend for the Rust language. It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust.
Quick Start
https://rust-analyzer.github.io/manual.html#installation
Documentation
If you want to contribute to rust-analyzer or are just curious about how things work under the hood, check the ./docs/dev folder.
If you want to use rust-analyzer's language server with your editor of choice, check the manual folder. It also contains some tips & tricks to help you be more productive when using rust-analyzer.
Security and Privacy
See the corresponding sections of the manual.
Communication
For usage and troubleshooting requests, please use "IDEs and Editors" category of the Rust forum:
https://users.rust-lang.org/c/ide/14
For questions about development and implementation, join rust-analyzer working group on Zulip:
https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer
Quick Links
- Website: https://rust-analyzer.github.io/
- Metrics: https://rust-analyzer.github.io/metrics/
- API docs: https://rust-lang.github.io/rust-analyzer/ide/
- Changelog: https://rust-analyzer.github.io/thisweek
License
rust-analyzer is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.