-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from rust-lang/rust-1.34
update edition guide for Rust 1.34
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Alternative Cargo registries | ||
|
||
Initially added: ![Minimum Rust version: 1.34](https://img.shields.io/badge/Minimum%20Rust%20Version-1.34-brightgreen.svg) | ||
|
||
For various reasons, you may not want to publish code to crates.io, but you | ||
may want to share it with others. For example, maybe your company writes Rust | ||
code that's not open source, but you'd still like to use these internal | ||
packages. | ||
|
||
Cargo supports alternative registries by settings in `.cargo/config`: | ||
|
||
```toml | ||
[registries] | ||
my-registry = { index = "https://my-intranet:7878/git/index" } | ||
``` | ||
|
||
When you want to depend on a package from another registry, you add that | ||
in to your `Cargo.toml`: | ||
|
||
```toml | ||
[dependencies] | ||
other-crate = { version = "1.0", registry = "my-registry" } | ||
``` | ||
|
||
To learn more, check out the [registries section of the Cargo | ||
book](https://doc.rust-lang.org/nightly/cargo/reference/registries.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# TryFrom and TryInto | ||
|
||
Initially added: ![Minimum Rust version: 1.34](https://img.shields.io/badge/Minimum%20Rust%20Version-1.34-brightgreen.svg) | ||
|
||
The [`TryFrom`](../../std/convert/trait.TryFrom.html) and | ||
[`TryInto`](../../std/convert/trait.TryInto.html) traits are like the | ||
[`From`](../../std/convert/trait.From.html) and | ||
[`Into`](../../std/convert/trait.Into.html) traits, except that they return a | ||
result, meaning that they may fail. | ||
|
||
For example, the `from_be_bytes` and related methods on integer types take | ||
arrays, but data is often read in via slices. Converting between slices and | ||
arrays is tedious to do manually. With the new traits, it can be done inline | ||
with `.try_into()`: | ||
|
||
```rust | ||
use std::convert::TryInto; | ||
# fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
# let slice = &[1, 2, 3, 4][..]; | ||
let num = u32::from_be_bytes(slice.try_into()?); | ||
# Ok(()) | ||
# } | ||
``` |