Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update edition guide for Rust 1.34 #215

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
# }
```