/// Returns the path to this `libclang` shared library. pubfn path(&self) -> &Path {
&self.path
}
/// Returns the (minimum) version of this `libclang` shared library. /// /// If this returns `None`, it indicates that the version is too old /// to be supported by this crate (i.e., `3.4` or earlier). If the /// version of this shared library is more recent than that fully /// supported by this crate, the most recent fully supported version /// will be returned. pubfn version(&self) -> Option<Version> {
macro_rules! check {
($fn:expr, $version:ident) => { ifself.library.get::<unsafeexternfn()>($fn).is_ok() { return Some(Version::$version);
}
};
}
/// Returns whether a `libclang` shared library is loaded on this thread. pubfn is_loaded() -> bool {
LIBRARY.with(|l| l.borrow().is_some())
}
fn with_library<T, F>(f: F) -> Option<T> where F: FnOnce(&SharedLibrary) -> T {
LIBRARY.with(|l| { match l.borrow().as_ref() {
Some(library) => Some(f(&library)),
_ => None,
}
})
}
$( #[cfg_attr(feature="cargo-clippy", allow(clippy::missing_safety_doc))] #[cfg_attr(feature="cargo-clippy", allow(clippy::too_many_arguments))]
$(#[doc=$doc] #[cfg($cfg)])* pubunsafefn $name($($pname: $pty), *) $(-> $ret)* { let f = with_library(|library| { iflet Some(function) = library.functions.$name {
function
} else {
panic!(
r#"
A `libclang` function was called that is not supported by the loaded `libclang` instance.
called function = `{0}`
loaded `libclang` instance = {1}
This crate only supports `libclang` 3.5 and later.
The minimum `libclang` requirement for this particular function can be found here:
https://docs.rs/clang-sys/latest/clang_sys/{0}/index.html
Instructions for installing `libclang` can be found here:
https://rust-lang.github.io/rust-bindgen/requirements.html "#,
stringify!($name),
library
.version()
.map(|v| format!("{}", v))
.unwrap_or_else(|| "unsupported version".into()),
);
}
}).expect("a `libclang` shared library is not loaded on this thread");
f($($pname), *)
}
/// Loads a `libclang` shared library and returns the library instance. /// /// This function does not attempt to load any functions from the shared library. The caller /// is responsible for loading the functions they require. /// /// # Failures /// /// * a `libclang` shared library could not be found /// * the `libclang` shared library could not be opened pubfn load_manually() -> Result<SharedLibrary, String> { #[allow(dead_code)] mod build {
include!(concat!(env!("OUT_DIR"), "/macros.rs")); pubmod common { include!(concat!(env!("OUT_DIR"), "/common.rs")); } pubmod dynamic { include!(concat!(env!("OUT_DIR"), "/dynamic.rs")); }
}
let (directory, filename) = build::dynamic::find(true)?; let path = directory.join(filename);
unsafe { let library = libloading::Library::new(&path).map_err(|e| {
format!( "the `libclang` shared library at {} could not be opened: {}",
path.display(),
e,
)
});
/// Loads a `libclang` shared library for use in the current thread. /// /// This functions attempts to load all the functions in the shared library. Whether a /// function has been loaded can be tested by calling the `is_loaded` function on the /// module with the same name as the function (e.g., `clang_createIndex::is_loaded()` for /// the `clang_createIndex` function). /// /// # Failures /// /// * a `libclang` shared library could not be found /// * the `libclang` shared library could not be opened #[allow(dead_code)] pubfn load() -> Result<(), String> { let library = Arc::new(load_manually()?);
LIBRARY.with(|l| *l.borrow_mut() = Some(library));
Ok(())
}
/// Unloads the `libclang` shared library in use in the current thread. /// /// # Failures /// /// * a `libclang` shared library is not in use in the current thread pubfn unload() -> Result<(), String> { let library = set_library(None); if library.is_some() {
Ok(())
} else {
Err("a `libclang` shared library is not in use in the current thread".into())
}
}
/// Returns the library instance stored in TLS. /// /// This functions allows for sharing library instances between threads. pubfn get_library() -> Option<Arc<SharedLibrary>> {
LIBRARY.with(|l| l.borrow_mut().clone())
}
/// Sets the library instance stored in TLS and returns the previous library. /// /// This functions allows for sharing library instances between threads. pubfn set_library(library: Option<Arc<SharedLibrary>>) -> Option<Arc<SharedLibrary>> {
LIBRARY.with(|l| mem::replace(&mut *l.borrow_mut(), library))
}
)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.