@@ -21,16 +21,13 @@ libc = "0.2.0"
2121
2222[ libc ] : https://crates.io/crates/libc
2323
24- and add ` extern crate libc; ` to your crate root.
25-
2624## Calling foreign functions
2725
2826The following is a minimal example of calling a foreign function which will
2927compile if snappy is installed:
3028
3129<!-- ignore: requires libc crate -->
3230``` rust,ignore
33- extern crate libc;
3431use libc::size_t;
3532
3633#[link(name = "snappy")]
@@ -64,7 +61,6 @@ The `extern` block can be extended to cover the entire snappy API:
6461
6562<!-- ignore: requires libc crate -->
6663``` rust,ignore
67- extern crate libc;
6864use libc::{c_int, size_t};
6965
7066#[link(name = "snappy")]
@@ -100,7 +96,6 @@ the allocated memory. The length is less than or equal to the capacity.
10096
10197<!-- ignore: requires libc crate -->
10298``` rust,ignore
103- # extern crate libc;
10499# use libc::{c_int, size_t};
105100# unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 }
106101# fn main() {}
@@ -125,7 +120,6 @@ the true length after compression for setting the length.
125120
126121<!-- ignore: requires libc crate -->
127122``` rust,ignore
128- # extern crate libc;
129123# use libc::{size_t, c_int};
130124# unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8,
131125# d: *mut size_t) -> c_int { 0 }
@@ -152,7 +146,6 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
152146
153147<!-- ignore: requires libc crate -->
154148``` rust,ignore
155- # extern crate libc;
156149# use libc::{size_t, c_int};
157150# unsafe fn snappy_uncompress(compressed: *const u8,
158151# compressed_length: size_t,
@@ -187,7 +180,6 @@ Then, we can add some tests to show how to use them.
187180
188181<!-- ignore: requires libc crate -->
189182``` rust,ignore
190- # extern crate libc;
191183# use libc::{c_int, size_t};
192184# unsafe fn snappy_compress(input: *const u8,
193185# input_length: size_t,
@@ -208,7 +200,7 @@ Then, we can add some tests to show how to use them.
208200# compressed_length: size_t)
209201# -> c_int { 0 }
210202# fn main() { }
211-
203+ #
212204#[cfg(test)]
213205mod tests {
214206 use super::*;
@@ -460,8 +452,6 @@ blocks with the `static` keyword:
460452
461453<!-- ignore: requires libc crate -->
462454``` rust,ignore
463- extern crate libc;
464-
465455#[link(name = "readline")]
466456extern {
467457 static rl_readline_version: libc::c_int;
@@ -479,8 +469,6 @@ them.
479469
480470<!-- ignore: requires libc crate -->
481471``` rust,ignore
482- extern crate libc;
483-
484472use std::ffi::CString;
485473use std::ptr;
486474
@@ -512,8 +500,6 @@ conventions. Rust provides a way to tell the compiler which convention to use:
512500
513501<!-- ignore: requires libc crate -->
514502``` rust,ignore
515- extern crate libc;
516-
517503#[cfg(all(target_os = "win32", target_arch = "x86"))]
518504#[link(name = "kernel32")]
519505#[allow(non_snake_case)]
@@ -624,7 +610,6 @@ we have function pointers flying across the FFI boundary in both directions.
624610
625611<!-- ignore: requires libc crate -->
626612``` rust,ignore
627- extern crate libc;
628613use libc::c_int;
629614
630615# #[cfg(hidden)]
@@ -724,8 +709,6 @@ We can represent this in Rust with the `c_void` type:
724709
725710<!-- ignore: requires libc crate -->
726711```rust,ignore
727- extern crate libc;
728-
729712extern "C" {
730713 pub fn foo(arg: *mut libc::c_void);
731714 pub fn bar(arg: *mut libc::c_void);
0 commit comments