asdf/lib.rs
1//! The C ABI for libasdf, implemented in Rust.
2//!
3//! This crate is a thin projection of [`asdf_core`] onto libasdf's exported
4//! C interface. It holds no behaviour of its own: everything here converts
5//! between C representations and the engine's, and every entry point is
6//! wrapped so that a panic can never unwind into a C caller.
7//!
8//! # What lives here versus in C
9//!
10//! Almost all of the ABI is expressed directly in Rust. Two things cannot be,
11//! and live in `shim.c` instead:
12//!
13//! - the three variadic entry points (`asdf_file_log`,
14//! `asdf_file_error_common`, `asdf_value_error_common`), because defining
15//! variadic `extern "C"` functions needs unstable Rust; and
16//! - `asdf_ndarray_read_float16_at`, because `_Float16` is unstable and its
17//! return ABI differs from `uint16_t`'s.
18//!
19//! # Headers
20//!
21//! The public headers are vendored verbatim from upstream rather than
22//! generated, because several API entry points exist only as `_Generic`
23//! macros or `static inline` functions. See `include/PROVENANCE.md`.
24
25#![allow(non_camel_case_types)]
26
27// Named so `alloc::` paths can be written directly. The crate links `std`,
28// but spelling each item at the narrowest layer that defines it keeps a
29// future `no_std` build a small step away.
30extern crate alloc;
31
32pub mod block_ffi;
33pub mod core_ext;
34pub mod error_ffi;
35pub mod extension_ffi;
36/// Internal only: the raw-pointer helpers every entry point is built on.
37pub(crate) mod ffi;
38pub mod file_ffi;
39pub mod ndarray_ffi;
40pub mod panic;
41pub mod parser_ffi;
42pub mod time_ffi;
43pub mod trampoline;
44pub mod types;
45pub mod util_ffi;
46pub mod value_ffi;
47pub mod version_ffi;
48
49pub use error_ffi::LogLevel;
50pub use file_ffi::{AsdfFile, AsdfValue};
51pub use types::{AsdfValueErr, AsdfValueType, asdf_config_t};
52pub use version_ffi::asdf_version_t;
53
54/// The library's own version, exported as `libasdf_version`.
55///
56/// Reported in the `asdf_library` metadata of files this library writes.
57pub const LIBASDF_RS_VERSION: &str = env!("CARGO_PKG_VERSION");