@@ -21,16 +21,13 @@ libc = "0.2.0"
21
21
22
22
[ libc ] : https://crates.io/crates/libc
23
23
24
- and add ` extern crate libc; ` to your crate root.
25
-
26
24
## Calling foreign functions
27
25
28
26
The following is a minimal example of calling a foreign function which will
29
27
compile if snappy is installed:
30
28
31
29
<!-- ignore: requires libc crate -->
32
30
``` rust,ignore
33
- extern crate libc;
34
31
use libc::size_t;
35
32
36
33
#[link(name = "snappy")]
@@ -64,7 +61,6 @@ The `extern` block can be extended to cover the entire snappy API:
64
61
65
62
<!-- ignore: requires libc crate -->
66
63
``` rust,ignore
67
- extern crate libc;
68
64
use libc::{c_int, size_t};
69
65
70
66
#[link(name = "snappy")]
@@ -100,7 +96,6 @@ the allocated memory. The length is less than or equal to the capacity.
100
96
101
97
<!-- ignore: requires libc crate -->
102
98
``` rust,ignore
103
- # extern crate libc;
104
99
# use libc::{c_int, size_t};
105
100
# unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 }
106
101
# fn main() {}
@@ -125,7 +120,6 @@ the true length after compression for setting the length.
125
120
126
121
<!-- ignore: requires libc crate -->
127
122
``` rust,ignore
128
- # extern crate libc;
129
123
# use libc::{size_t, c_int};
130
124
# unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8,
131
125
# d: *mut size_t) -> c_int { 0 }
@@ -152,7 +146,6 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
152
146
153
147
<!-- ignore: requires libc crate -->
154
148
``` rust,ignore
155
- # extern crate libc;
156
149
# use libc::{size_t, c_int};
157
150
# unsafe fn snappy_uncompress(compressed: *const u8,
158
151
# compressed_length: size_t,
@@ -187,7 +180,6 @@ Then, we can add some tests to show how to use them.
187
180
188
181
<!-- ignore: requires libc crate -->
189
182
``` rust,ignore
190
- # extern crate libc;
191
183
# use libc::{c_int, size_t};
192
184
# unsafe fn snappy_compress(input: *const u8,
193
185
# input_length: size_t,
@@ -208,7 +200,7 @@ Then, we can add some tests to show how to use them.
208
200
# compressed_length: size_t)
209
201
# -> c_int { 0 }
210
202
# fn main() { }
211
-
203
+ #
212
204
#[cfg(test)]
213
205
mod tests {
214
206
use super::*;
@@ -460,8 +452,6 @@ blocks with the `static` keyword:
460
452
461
453
<!-- ignore: requires libc crate -->
462
454
``` rust,ignore
463
- extern crate libc;
464
-
465
455
#[link(name = "readline")]
466
456
extern {
467
457
static rl_readline_version: libc::c_int;
@@ -479,8 +469,6 @@ them.
479
469
480
470
<!-- ignore: requires libc crate -->
481
471
``` rust,ignore
482
- extern crate libc;
483
-
484
472
use std::ffi::CString;
485
473
use std::ptr;
486
474
@@ -512,8 +500,6 @@ conventions. Rust provides a way to tell the compiler which convention to use:
512
500
513
501
<!-- ignore: requires libc crate -->
514
502
``` rust,ignore
515
- extern crate libc;
516
-
517
503
#[cfg(all(target_os = "win32", target_arch = "x86"))]
518
504
#[link(name = "kernel32")]
519
505
#[allow(non_snake_case)]
@@ -624,7 +610,6 @@ we have function pointers flying across the FFI boundary in both directions.
624
610
625
611
<!-- ignore: requires libc crate -->
626
612
``` rust,ignore
627
- extern crate libc;
628
613
use libc::c_int;
629
614
630
615
# #[cfg(hidden)]
@@ -724,8 +709,6 @@ We can represent this in Rust with the `c_void` type:
724
709
725
710
<!-- ignore: requires libc crate -->
726
711
```rust,ignore
727
- extern crate libc;
728
-
729
712
extern "C" {
730
713
pub fn foo(arg: *mut libc::c_void);
731
714
pub fn bar(arg: *mut libc::c_void);
0 commit comments