Skip to content

Commit 0fe83ab

Browse files
authored
Merge pull request #510 from memark/patch-1
Fix grammar in ffi.md
2 parents 9fef1fa + b1e9226 commit 0fe83ab

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/ffi.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ snappy includes a C interface (documented in
1111
## A note about libc
1212

1313
Many of these examples use [the `libc` crate][libc], which provides various
14-
type definitions for C types, among other things. If you’re trying these
14+
type definitions for C types, among other things. If you’re trying out these
1515
examples yourself, you’ll need to add `libc` to your `Cargo.toml`:
1616

1717
```toml
@@ -23,9 +23,8 @@ libc = "0.2.0"
2323

2424
## Prepare the build script
2525

26-
Because [snappy](https://github.com/google/snappy) is a static library by default.
27-
So there is no C++ std linked in the output artifact.
28-
In order to use this foreign library in Rust, we have to manually specify that we want to link stdc++ in our project.
26+
Because [snappy](https://github.com/google/snappy) is a static library by default, so there is no stdc++ linked in the output artifact.
27+
In order to use this foreign library in Rust, we have to manually specify that we want to link stdc++ std to our project.
2928
The easiest way to do this is by setting up a build script.
3029

3130
First edit `Cargo.toml`, inside `package` add `build = "build.rs"`:
@@ -39,7 +38,7 @@ Then create a new file at the root of your workspace, named `build.rs`:
3938
```rust
4039
// build.rs
4140
fn main() {
42-
println!("cargo:rustc-link-lib=dylib=stdc++"); // This line may be unnecessary for some environment.
41+
println!("cargo:rustc-link-lib=dylib=stdc++"); // This line may be unnecessary for some environments.
4342
println!("cargo:rustc-link-search=<YOUR SNAPPY LIBRARY PATH>");
4443
}
4544
```
@@ -69,7 +68,7 @@ fn main() {
6968

7069
The `extern` block is a list of function signatures in a foreign library, in
7170
this case with the platform's C ABI. The `#[link(...)]` attribute is used to
72-
instruct the linker to link against the snappy library so the symbols are
71+
instruct the linker to link against the snappy library so the symbols can be
7372
resolved.
7473

7574
Foreign functions are assumed to be unsafe so calls to them need to be wrapped
@@ -115,7 +114,7 @@ The raw C API needs to be wrapped to provide memory safety and make use of highe
115114
like vectors. A library can choose to expose only the safe, high-level interface and hide the unsafe
116115
internal details.
117116

118-
Wrapping the functions which expect buffers involves using the `slice::raw` module to manipulate Rust
117+
Wrapping the functions which expect buffers involves using the `slice::raw` module to manipulate Rust's
119118
vectors as pointers to memory. Rust's vectors are guaranteed to be a contiguous block of memory. The
120119
length is the number of elements currently contained, and the capacity is the total size in elements of
121120
the allocated memory. The length is less than or equal to the capacity.
@@ -262,13 +261,13 @@ mod tests {
262261

263262
Foreign libraries often hand off ownership of resources to the calling code.
264263
When this occurs, we must use Rust's destructors to provide safety and guarantee
265-
the release of these resources (especially in the case of panic).
264+
the release of these resources (especially in the case of a panic).
266265

267-
For more about destructors, see the [Drop trait](../std/ops/trait.Drop.html).
266+
For more information about destructors, see the [Drop trait](../std/ops/trait.Drop.html).
268267

269268
## Calling Rust code from C
270269

271-
You may wish to compile Rust code in a way so that it can be called from C.
270+
You may wish to compile Rust code in a way that can be called from C.
272271
This is fairly easy, but requires a few things.
273272

274273
### Rust side
@@ -294,7 +293,7 @@ Then, to compile Rust code as a shared library that can be called from C, add th
294293
crate-type = ["cdylib"]
295294
```
296295

297-
(NOTE: We could also use the `staticlib` crate type but it needs to tweak some linking flags.)
296+
(NOTE: We could also use the `staticlib` crate type but it also requires tweaking some linking flags.)
298297

299298
Run `cargo build` and you're ready to go on the Rust side.
300299

@@ -332,7 +331,7 @@ Hello from Rust!
332331
```
333332

334333
That's it!
335-
For more realistic example, check the [`cbindgen`].
334+
For a more realistic example, check the [`cbindgen`].
336335

337336
[`cbindgen`]: https://github.com/eqrion/cbindgen
338337

@@ -621,7 +620,7 @@ This is currently hidden behind the `abi_vectorcall` gate and is subject to chan
621620
* `win64`
622621
* `sysv64`
623622

624-
Most of the abis in this list are self-explanatory, but the `system` abi may
623+
Most of the ABIs in this list are self-explanatory, but the `system` ABI may
625624
seem a little odd. This constraint selects whatever the appropriate ABI is for
626625
interoperating with the target's libraries. For example, on win32 with a x86
627626
architecture, this means that the abi used would be `stdcall`. On x86_64,

0 commit comments

Comments
 (0)