Skip to content

Commit 566330b

Browse files
committed
trpl: push cargo in FFI chapter
1 parent 9c9f95c commit 566330b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/doc/trpl/ffi.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55
This guide will use the [snappy](https://github.com/google/snappy)
66
compression/decompression library as an introduction to writing bindings for
77
foreign code. Rust is currently unable to call directly into a C++ library, but
8-
snappy includes a C interface (documented in
9-
[`snappy-c.h`](https://github.com/google/snappy/blob/master/snappy-c.h)).
8+
snappy includes a C interface (documented in [`snappy-c.h`][snappy-header]).
9+
10+
[snappy-header]: https://github.com/google/snappy/blob/master/snappy-c.h
11+
12+
Often when writing these bindings, types and functions from the C standard
13+
library will be necessary. These can be found in the
14+
[libc crate on crates.io][libc], which can be accessed in a Cargo project
15+
by [adding it as a dependency][cargo-add]. (Note that if you click the examples
16+
here to load them in the [playground](https://play.rust-lang.org), which doesn't
17+
support Cargo, you'll see extra lines of code to keep them compiling while
18+
remaining self-contained... but in your own projects you should use Cargo.)
19+
20+
[cargo-add]: http://doc.crates.io/guide.html#adding-a-dependency
1021

1122
The following is a minimal example of calling a foreign function which will
1223
compile if snappy is installed:
@@ -23,7 +34,7 @@ extern {
2334
}
2435
2536
# #[cfg(not(nope))] unsafe fn snappy_max_compressed_length(_: size_t) -> size_t { 0 }
26-
37+
#
2738
fn main() {
2839
let x = unsafe { snappy_max_compressed_length(100) };
2940
println!("max compressed length of a 100 byte buffer: {}", x);

0 commit comments

Comments
 (0)