From 98ef870b0f0273befa46a92b2d22c3a5b702ede6 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 6 Jul 2020 17:09:12 -0500 Subject: [PATCH] update edition guide for Rust 1.34 Fixes #203 --- src/SUMMARY.md | 4 ++- src/rust-next/alternative-cargo-registries.md | 26 +++++++++++++++++++ src/rust-next/tryfrom-and-tryinto.md | 23 ++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/rust-next/alternative-cargo-registries.md create mode 100644 src/rust-next/tryfrom-and-tryinto.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index c2f95668..1990b5dd 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) \ No newline at end of file + - [Pinning](rust-next/pin.md) + - [Alternative Cargo Registries](rust-next/alternative-cargo-registries.md) + - [TryFrom and TryInto](rust-next/tryfrom-and-tryinto.md) diff --git a/src/rust-next/alternative-cargo-registries.md b/src/rust-next/alternative-cargo-registries.md new file mode 100644 index 00000000..84e70672 --- /dev/null +++ b/src/rust-next/alternative-cargo-registries.md @@ -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). diff --git a/src/rust-next/tryfrom-and-tryinto.md b/src/rust-next/tryfrom-and-tryinto.md new file mode 100644 index 00000000..3c4be087 --- /dev/null +++ b/src/rust-next/tryfrom-and-tryinto.md @@ -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> { +# let slice = &[1, 2, 3, 4][..]; +let num = u32::from_be_bytes(slice.try_into()?); +# Ok(()) +# } +```