Skip to content

Commit fa817ea

Browse files
authored
Merge branch 'master' into rust-1.35
2 parents 08dc37a + c435b3d commit fa817ea

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,5 @@
9898
- [const fn](rust-next/const-fn.md)
9999
- [Pinning](rust-next/pin.md)
100100
- [No more FnBox](rust-next/no-more-fnbox.md)
101+
- [Alternative Cargo Registries](rust-next/alternative-cargo-registries.md)
102+
- [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)