Skip to content

Commit 939bc43

Browse files
committed
Trim down a paragraph a bit
1 parent fb731f5 commit 939bc43

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

_posts/2015-04-24-Rust-Once-Run-Everywhere.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ it talks to itself. For this reason, **Rust makes it easy to communicate with C
1111
APIs without overhead, and to leverage its ownership system to provide much
1212
stronger safety guarantees for those APIs at the same time**.
1313

14-
In more detail, Rust's *foreign function interface* (FFI) is the way that it
15-
communicated with other languages. Following Rust's design principles, the FFI
16-
provides a **zero-cost abstraction** where function calls between Rust and C
17-
have identical performance to C function calls. FFI bindings can also leverage
18-
language features such as ownership and borrowing to provide a **safe
19-
interface** that enforces protocols around pointers and other resources. These
20-
protocols usually appear only in the documentation for C APIs -- at best -- but
21-
Rust makes them explicit.
14+
To communicate with other languages, Rust provides a *foreign function
15+
interface* (FFI). Following Rust's design principles, the FFI provides a
16+
**zero-cost abstraction** where function calls between Rust and C have identical
17+
performance to C function calls. FFI bindings can also leverage language
18+
features such as ownership and borrowing to provide a **safe interface** that
19+
enforces protocols around pointers and other resources. These protocols usually
20+
appear only in the documentation for C APIs -- at best -- but Rust makes them
21+
explicit.
2222

2323
In this post we'll explore how to encapsulate unsafe FFI calls to C in safe,
2424
zero-cost abstractions. Working with C is, however, just an example; we'll also
@@ -157,16 +157,14 @@ impl Tarball {
157157
```
158158

159159
Here the `*mut tarball_t` pointer is *owned by* a `Tarball`, which is
160-
responsible for any destruction and cleanup. So we already have rich knowledge
161-
about the lifetime of the resource: if you have access to a `Tarball`, you know
162-
that the pointer inside must still be valid. Additionally, the `file` method
160+
responsible for any destruction and cleanup, so we already have rich knowledge
161+
about the lifetime of the tarball's memory. Additionally, the `file` method
163162
returns a **borrowed slice** whose lifetime is implicitly connected to the
164163
lifetime of the source tarball itself (the `&self` argument). This is Rust's way
165164
of indicating that the returned slice can only be used within the lifetime of
166-
the tarball, which in turn means that the slice will always point to valid
167-
memory. Thus, Rust statically prevents dangling pointer bugs that are easy to
165+
the tarball, statically preventing dangling pointer bugs that are easy to
168166
make when working directly with C. (If you're not familiar with this kind of
169-
borrowing in Rust, have a look at Yehuda Katz's [blog post] on ownership.)
167+
borrowing in Rust, have a look at Yehuda Katz's [blog post on ownership].)
170168

171169
[blog post]: http://blog.skylight.io/rust-means-never-having-to-close-a-socket/
172170

0 commit comments

Comments
 (0)