1 // We have a lot of c-types in here, stop warning about their names! 2 #![allow(non_camel_case_types)] 3 // fmt::Debug isn't helpful on FFI types 4 #![allow(missing_debug_implementations)] 5 // unreachable_pub warns `#[no_mangle] pub extern fn` in private mod. 6 #![allow(unreachable_pub)] 7 8 //! # hyper C API 9 //! 10 //! This part of the documentation describes the C API for hyper. That is, how 11 //! to *use* the hyper library in C code. This is **not** a regular Rust 12 //! module, and thus it is not accessible in Rust. 13 //! 14 //! ## Unstable 15 //! 16 //! The C API of hyper is currently **unstable**, which means it's not part of 17 //! the semver contract as the rest of the Rust API is. Because of that, it's 18 //! only accessible if `--cfg hyper_unstable_ffi` is passed to `rustc` when 19 //! compiling. The easiest way to do that is setting the `RUSTFLAGS` 20 //! environment variable. 21 //! 22 //! ## Building 23 //! 24 //! The C API is part of the Rust library, but isn't compiled by default. Using 25 //! `cargo`, it can be compiled with the following command: 26 //! 27 //! ```notrust 28 //! RUSTFLAGS="--cfg hyper_unstable_ffi" cargo build --features client,http1,http2,ffi 29 //! ``` 30 31 // We may eventually allow the FFI to be enabled without `client` or `http1`, 32 // that is why we don't auto enable them as `ffi = ["client", "http1"]` in 33 // the `Cargo.toml`. 34 // 35 // But for now, give a clear message that this compile error is expected. 36 #[cfg(not(all(feature = "client", feature = "http1")))] 37 compile_error!("The `ffi` feature currently requires the `client` and `http1` features."); 38 39 #[cfg(not(hyper_unstable_ffi))] 40 compile_error!( 41 "\ 42 The `ffi` feature is unstable, and requires the \ 43 `RUSTFLAGS='--cfg hyper_unstable_ffi'` environment variable to be set.\ 44 " 45 ); 46 47 #[macro_use] 48 mod macros; 49 50 mod body; 51 mod client; 52 mod error; 53 mod http_types; 54 mod io; 55 mod task; 56 57 pub use self::body::*; 58 pub use self::client::*; 59 pub use self::error::*; 60 pub use self::http_types::*; 61 pub use self::io::*; 62 pub use self::task::*; 63 64 /// Return in iter functions to continue iterating. 65 pub const HYPER_ITER_CONTINUE: libc::c_int = 0; 66 /// Return in iter functions to stop iterating. 67 #[allow(unused)] 68 pub const HYPER_ITER_BREAK: libc::c_int = 1; 69 70 /// An HTTP Version that is unspecified. 71 pub const HYPER_HTTP_VERSION_NONE: libc::c_int = 0; 72 /// The HTTP/1.0 version. 73 pub const HYPER_HTTP_VERSION_1_0: libc::c_int = 10; 74 /// The HTTP/1.1 version. 75 pub const HYPER_HTTP_VERSION_1_1: libc::c_int = 11; 76 /// The HTTP/2 version. 77 pub const HYPER_HTTP_VERSION_2: libc::c_int = 20; 78 79 struct UserDataPointer(*mut std::ffi::c_void); 80 81 // We don't actually know anything about this pointer, it's up to the user 82 // to do the right thing. 83 unsafe impl Send for UserDataPointer {} 84 unsafe impl Sync for UserDataPointer {} 85 86 /// cbindgen:ignore 87 static VERSION_CSTR: &str = concat!(env!("CARGO_PKG_VERSION"), "\0"); 88 89 ffi_fn! { 90 /// Returns a static ASCII (null terminated) string of the hyper version. 91 fn hyper_version() -> *const libc::c_char { 92 VERSION_CSTR.as_ptr() as _ 93 } ?= std::ptr::null() 94 } 95