Skip to content

Commit

Permalink
update edition guide for Rust 1.34
Browse files Browse the repository at this point in the history
Fixes #203
  • Loading branch information
steveklabnik committed Jul 6, 2020
1 parent 82bec58 commit 98ef870
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@
- [`literal` macro matcher](rust-next/literal-macro-matcher.md)
- [`?` operator in macros](rust-next/qustion-mark-operator-in-macros.md)
- [const fn](rust-next/const-fn.md)
- [Pinning](rust-next/pin.md)
- [Pinning](rust-next/pin.md)
- [Alternative Cargo Registries](rust-next/alternative-cargo-registries.md)
- [TryFrom and TryInto](rust-next/tryfrom-and-tryinto.md)
26 changes: 26 additions & 0 deletions src/rust-next/alternative-cargo-registries.md
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).
23 changes: 23 additions & 0 deletions src/rust-next/tryfrom-and-tryinto.md
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(())
# }
```

0 comments on commit 98ef870

Please sign in to comment.