Skip to main content

icu_capi/
lib.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
6#![cfg_attr(not(any(test, feature = "std")), no_std)]
7#![cfg_attr(
8    not(test),
9    deny(
10        clippy::indexing_slicing,
11        clippy::unwrap_used,
12        clippy::expect_used,
13        clippy::panic,
14        // Enums should be non-exhaustive, as exhaustive enums don't exist in other languages anyway
15        clippy::exhaustive_enums,
16        // Structs should be exhaustive, as they are exhaustive in C/C++
17        // Debug is not required as there is no stable Rust API
18    )
19)]
20// Diplomat limitations
21#![allow(
22    clippy::needless_lifetimes,
23    clippy::result_unit_err,
24    clippy::should_implement_trait
25)]
26// libc is behind a negative feature
27#![allow(unused_crate_dependencies)]
28
29//! This crate contains the `extern "C"` FFI for ICU4X, as well as the [Diplomat](https://github.com/rust-diplomat/diplomat)-generated
30//! C, C++, Dart, JavaScript, and TypeScript bindings.
31#![allow(rustdoc::invalid_html_tags)]
32// attribute split over three lines because `cargo generate-readmes` does not evaluate `#![doc = ]` docs
33//! <p style='font-weight: bold; font-size: 24px;'> 🔗 See the <a target='_blank' href='https://icu4x.unicode.org/
34#![cfg_attr(doc, doc = core::env!("CARGO_PKG_VERSION"))]
35//! '>ICU4X website</a> for FFI docs and examples</p>
36//!
37//! This crate is `no_std`-compatible, but requires an allocator. If you wish to use it in `no_std` mode, you can either
38//! enable the `looping_panic_handler` and `libc_alloc` Cargo features, or write a wrapper crate that defines an
39//! allocator/panic handler.
40//!
41//! <div class="stab unstable">
42//! 🚧 While the types in this crate are public, APIs from this crate are <em>not intended to be used from Rust</em> and as
43//! such this crate may unpredictably change its Rust API across compatible semver versions.
44//!
45//! The <code>extern "C"</code> APIs exposed by this crate, while not directly documented, are stable within the same major
46//! semver version, as are the bindings in the <code>bindings</code> folder.
47//! </div>
48
49// Renamed so you can't accidentally use it
50#[cfg(target_arch = "wasm32")]
51extern crate std as rust_std;
52
53#[cfg(all(not(feature = "std"), feature = "looping_panic_handler"))]
54#[panic_handler]
55fn panic(_info: &core::panic::PanicInfo) -> ! {
56    loop {}
57}
58
59extern crate alloc;
60#[cfg(all(not(feature = "std"), feature = "libc_alloc"))]
61extern crate libc_alloc;
62
63#[cfg(feature = "datetime")]
64pub(crate) mod datetime_helpers;
65
66/// The Rust API of this crate is **UNSTABLE**; this crate is primarily intended
67/// to be used from its FFI bindings, packaged with the crate.
68///
69/// The C ABI layer is stable.
70#[path = "."] // https://github.com/rust-lang/rust/issues/35016
71pub mod unstable {
72    // Common modules
73    pub mod errors;
74    pub mod locale_core;
75    #[cfg(feature = "logging")]
76    pub mod logging;
77    #[macro_use]
78    pub mod provider;
79
80    // Components
81
82    #[cfg(feature = "properties")]
83    pub mod bidi;
84    #[cfg(feature = "calendar")]
85    pub mod calendar;
86    #[cfg(feature = "casemap")]
87    pub mod casemap;
88    #[cfg(feature = "collator")]
89    pub mod collator;
90    #[cfg(feature = "properties")]
91    pub mod collections_sets;
92    #[cfg(feature = "calendar")]
93    pub mod date;
94    #[cfg(feature = "datetime")]
95    pub mod date_formatter;
96    #[cfg(feature = "datetime")]
97    pub mod date_time_formatter;
98    #[cfg(feature = "calendar")]
99    pub mod datetime;
100    #[cfg(feature = "datetime")]
101    pub mod datetime_options;
102    #[cfg(feature = "decimal")]
103    pub mod decimal;
104    #[cfg(feature = "experimental")]
105    pub mod displaynames;
106    #[cfg(feature = "locale")]
107    pub mod exemplar_chars;
108    #[cfg(feature = "locale")]
109    pub mod fallbacker;
110    #[cfg(feature = "decimal")]
111    pub mod fixed_decimal;
112    #[cfg(feature = "datetime")]
113    pub mod iana_parser;
114    #[cfg(feature = "list")]
115    pub mod list;
116    #[cfg(feature = "locale")]
117    pub mod locale;
118    #[cfg(feature = "locale")]
119    pub mod locale_directionality;
120    #[cfg(feature = "normalizer")]
121    pub mod normalizer;
122    #[cfg(feature = "normalizer")]
123    pub mod normalizer_properties;
124    #[cfg(feature = "plurals")]
125    pub mod pluralrules;
126    #[cfg(feature = "properties")]
127    pub mod properties_bidi;
128    #[cfg(feature = "properties")]
129    pub mod properties_enums;
130    #[cfg(feature = "properties")]
131    pub mod properties_iter;
132    #[cfg(feature = "properties")]
133    pub mod properties_maps;
134    #[cfg(feature = "properties")]
135    pub mod properties_names;
136    #[cfg(feature = "properties")]
137    pub mod properties_sets;
138    #[cfg(feature = "properties")]
139    pub mod properties_unisets;
140    #[cfg(feature = "properties")]
141    pub mod script;
142    #[cfg(feature = "segmenter")]
143    pub mod segmenter_grapheme;
144    #[cfg(feature = "segmenter")]
145    pub mod segmenter_line;
146    #[cfg(feature = "segmenter")]
147    pub mod segmenter_sentence;
148    #[cfg(feature = "segmenter")]
149    pub mod segmenter_word;
150    #[cfg(feature = "calendar")]
151    pub mod time;
152    #[cfg(feature = "datetime")]
153    pub mod time_formatter;
154    #[cfg(feature = "datetime")]
155    pub mod timezone;
156    #[cfg(feature = "datetime")]
157    pub mod timezone_formatter;
158    #[cfg(feature = "datetime")]
159    pub mod variant_offset;
160    #[cfg(feature = "calendar")]
161    pub mod week;
162    #[cfg(feature = "datetime")]
163    pub mod windows_parser;
164    #[cfg(feature = "datetime")]
165    pub mod zoned_date_formatter;
166    #[cfg(feature = "datetime")]
167    pub mod zoned_date_time_formatter;
168    #[cfg(feature = "datetime")]
169    pub mod zoned_datetime;
170    #[cfg(feature = "datetime")]
171    pub mod zoned_time_formatter;
172}