Skip to content

Commit

Permalink
Fixes for doc tests
Browse files Browse the repository at this point in the history
There is still a "local ambiguity when calling macro `external_library`"
error. That appears to be a real bug.
  • Loading branch information
ids1024 committed Oct 16, 2024
1 parent 7ebedc8 commit 5a7fc8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions dlib-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use dlib::external_library;

external_library!(Mlib, "m",
statics:
#[cfg(feature = "nonexistant")]
non_existant_static: f64,
functions:
fn cos(f64) -> f64,
#[cfg(feature = "sin")]
fn sin(f64) -> f64,
#[cfg(feature = "nonexistant")]
fn nonexistant_function(f64) -> f64,
varargs:
#[cfg(feature = "nonexistant")]
fn nonexistant_varargs(f64 ...) -> f64,
);

#[cfg(feature = "dlopen")]
Expand Down
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! dlib defines the `external_library!` macro, which can be invoked in this way:
//!
//! ```rust
//! # use dlib::external_library;
//! # use std::ffi::{c_float, c_int};
//! external_library!(feature="dlopen-foo", Foo, "foo",
//! statics:
//! me: c_int,
Expand All @@ -28,7 +30,8 @@
//! this macro will expand to an extern block defining each of the items, using the third argument
//! of the macro as a link name:
//!
//! ```rust
//! ```rust no_run
//! # use std::ffi::{c_float, c_int, c_void};
//! #[link(name = "foo")]
//! extern "C" {
//! pub static me: c_int;
Expand All @@ -47,6 +50,8 @@
//! and a method `open`, which tries to load the library from the name or path given as an argument.
//!
//! ```rust
//! # use dlib::DlError;
//! # use std::ffi::{c_float, c_int, c_void};
//! pub struct Foo {
//! pub me: &'static c_int,
//! pub you: &'static c_float,
Expand All @@ -59,7 +64,10 @@
//!
//!
//! impl Foo {
//! pub unsafe fn open(name: &str) -> Result<Foo, DlError> { /* ... */ }
//! pub unsafe fn open(name: &str) -> Result<Foo, DlError> {
//! /* ... */
//! # todo!()
//! }
//! }
//! ```
//!
Expand Down Expand Up @@ -90,7 +98,9 @@
//!
//! Then give the name of that feature as the `feature` argument to dlib's macros:
//!
//! ```rust
//! ```rust no_run
//! # use dlib::external_library;
//! # use std::ffi::c_int;
//! external_library!(feature="dlopen-foo", Foo, "foo",
//! functions:
//! fn foo() -> c_int,
Expand All @@ -99,7 +109,12 @@
//!
//! `dlib` provides helper macros to dispatch the access to foreign symbols:
//!
//! ```rust
//! ```rust no_run
//! # use dlib::{ffi_dispatch, ffi_dispatch_static};
//! # let arg1 = todo!();
//! # let arg2 = todo!();
//! # let function: fn(u32, u32) = todo!();
//! # let my_static_var = todo!();
//! ffi_dispatch!(feature="dlopen-foo", Foo, function, arg1, arg2);
//! ffi_dispatch_static!(feature="dlopen-foo", Foo, my_static_var);
//! ```
Expand All @@ -122,6 +137,8 @@
//! Then, it can become as simple as putting this on top of all modules using the FFI:
//!
//! ```rust
//! # #![allow(unexpected_cfgs)]
//! # mod ffi {}
//! #[cfg(feature = "dlopen-foo")]
//! use ffi::FOO_STATIC;
//! #[cfg(not(feature = "dlopen-foo"))]
Expand Down

0 comments on commit 5a7fc8a

Please sign in to comment.