Skip to content

Commit c435b3d

Browse files
authored
Merge pull request #215 from rust-lang/rust-1.34
update edition guide for Rust 1.34
2 parents 82bec58 + 98ef870 commit c435b3d

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/SUMMARY.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@
9696
- [`literal` macro matcher](rust-next/literal-macro-matcher.md)
9797
- [`?` operator in macros](rust-next/qustion-mark-operator-in-macros.md)
9898
- [const fn](rust-next/const-fn.md)
99-
- [Pinning](rust-next/pin.md)
99+
- [Pinning](rust-next/pin.md)
100+
- [Alternative Cargo Registries](rust-next/alternative-cargo-registries.md)
101+
- [TryFrom and TryInto](rust-next/tryfrom-and-tryinto.md)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Alternative Cargo registries
2+
3+
Initially added: ![Minimum Rust version: 1.34](https://img.shields.io/badge/Minimum%20Rust%20Version-1.34-brightgreen.svg)
4+
5+
For various reasons, you may not want to publish code to crates.io, but you
6+
may want to share it with others. For example, maybe your company writes Rust
7+
code that's not open source, but you'd still like to use these internal
8+
packages.
9+
10+
Cargo supports alternative registries by settings in `.cargo/config`:
11+
12+
```toml
13+
[registries]
14+
my-registry = { index = "https://my-intranet:7878/git/index" }
15+
```
16+
17+
When you want to depend on a package from another registry, you add that
18+
in to your `Cargo.toml`:
19+
20+
```toml
21+
[dependencies]
22+
other-crate = { version = "1.0", registry = "my-registry" }
23+
```
24+
25+
To learn more, check out the [registries section of the Cargo
26+
book](https://doc.rust-lang.org/nightly/cargo/reference/registries.html).

src/rust-next/tryfrom-and-tryinto.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# TryFrom and TryInto
2+
3+
Initially added: ![Minimum Rust version: 1.34](https://img.shields.io/badge/Minimum%20Rust%20Version-1.34-brightgreen.svg)
4+
5+
The [`TryFrom`](../../std/convert/trait.TryFrom.html) and
6+
[`TryInto`](../../std/convert/trait.TryInto.html) traits are like the
7+
[`From`](../../std/convert/trait.From.html) and
8+
[`Into`](../../std/convert/trait.Into.html) traits, except that they return a
9+
result, meaning that they may fail.
10+
11+
For example, the `from_be_bytes` and related methods on integer types take
12+
arrays, but data is often read in via slices. Converting between slices and
13+
arrays is tedious to do manually. With the new traits, it can be done inline
14+
with `.try_into()`:
15+
16+
```rust
17+
use std::convert::TryInto;
18+
# fn main() -> Result<(), Box<dyn std::error::Error>> {
19+
# let slice = &[1, 2, 3, 4][..];
20+
let num = u32::from_be_bytes(slice.try_into()?);
21+
# Ok(())
22+
# }
23+
```

0 commit comments

Comments
 (0)