Skip to content

Add missing first_or function to ch04-02-references-and-borrowing.md #273

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion src/ch04-02-references-and-borrowing.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ This snippet introduces a new kind of permission, the flow permission @Perm{flow

Unlike the @Perm{read}@Perm{write}@Perm{own} permissions, @Perm{flow} does not change throughout the body of a function. A reference has the @Perm{flow} permission if it's allowed to be used (that is, to *flow*) in a particular expression. For example, let's say we change `first` to a new function `first_or` that includes a `default` parameter:

```aquascope,permissions,boundaries,showFlows
fn first_or(strings: &Vec<String>, default: &String) -> &String {
let s_ref = &strings[0];
s_ref`{}`
}
```

This function no longer compiles, because the expressions `&strings[0]` and `default` lack the necessary @Perm{flow} permission to be returned. But why? Rust gives the following error:

```text
Expand Down Expand Up @@ -451,4 +458,4 @@ In this section, it probably feels like we've described more of what Rust _canno

[`String::push_str`]: https://doc.rust-lang.org/std/string/struct.String.html#method.push_str
[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
[`Vec::push`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.push
[`Vec::push`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.push