rust_icu_sys/
lib.rs

1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Notes:
16// * deref_nullptr: since rustc 1.53, bindgen causes UB warnings -- see
17// https://github.com/rust-lang/rust-bindgen/issues/1651 remove this once bindgen has fixed the
18// issue (currently at version 1.59.1)
19#![allow(
20    dead_code,
21    non_snake_case,
22    non_camel_case_types,
23    non_upper_case_globals,
24    unused_imports,
25    rustdoc::bare_urls,
26    deref_nullptr
27)]
28
29#[cfg(all(feature = "icu_version_in_env", feature = "icu_config"))]
30compile_error!(
31    "Features `icu_version_in_env` and `icu_config` are not compatible."
32        + " Choose at most one of them."
33);
34
35#[cfg(all(feature = "icu_config", not(feature = "use-bindgen")))]
36compile_error!("Feature `icu_config` is useless without the feature `use-bindgen`");
37
38// This feature combination is not inherrently a problem; we had no use case that
39// required it just yet.
40#[cfg(all(not(feature = "renaming"), not(feature = "use-bindgen")))]
41compile_error!("You must use `renaming` when not using `use-bindgen`");
42
43#[cfg(feature = "use-bindgen")]
44include!(concat!(env!("OUT_DIR"), "/macros.rs"));
45#[cfg(all(
46    feature = "use-bindgen",
47    feature = "icu_config",
48    not(feature = "icu_version_in_env")
49))]
50include!(concat!(env!("OUT_DIR"), "/lib.rs"));
51
52#[cfg(not(feature = "use-bindgen"))]
53include!("../bindgen/macros.rs");
54
55#[cfg(all(
56    not(feature = "use-bindgen"),
57    not(feature = "icu_version_in_env"),
58    not(feature = "icu_config")
59))]
60include!("../bindgen/lib.rs");
61
62#[cfg(all(
63    not(feature = "use-bindgen"),
64    feature = "icu_version_in_env",
65    not(feature = "icu_config")
66))]
67include!(concat!(
68    "../bindgen/lib_",
69    env!("RUST_ICU_MAJOR_VERSION_NUMBER"),
70    ".rs"
71));
72
73// Add the ability to print the error code, so that it can be reported in
74// aggregated errors.
75impl std::fmt::Display for UErrorCode {
76    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
77        write!(f, "{:?}", self)
78    }
79}
80
81extern crate libc;
82
83impl From<i8> for UCharCategory {
84    fn from(value: i8) -> Self {
85        match value {
86            0 => UCharCategory::U_UNASSIGNED,
87            1 => UCharCategory::U_UPPERCASE_LETTER,
88            2 => UCharCategory::U_LOWERCASE_LETTER,
89            3 => UCharCategory::U_TITLECASE_LETTER,
90            4 => UCharCategory::U_MODIFIER_LETTER,
91            5 => UCharCategory::U_OTHER_LETTER,
92            6 => UCharCategory::U_NON_SPACING_MARK,
93            7 => UCharCategory::U_ENCLOSING_MARK,
94            8 => UCharCategory::U_COMBINING_SPACING_MARK,
95            9 => UCharCategory::U_DECIMAL_DIGIT_NUMBER,
96            10 => UCharCategory::U_LETTER_NUMBER,
97            11 => UCharCategory::U_OTHER_NUMBER,
98            12 => UCharCategory::U_SPACE_SEPARATOR,
99            13 => UCharCategory::U_LINE_SEPARATOR,
100            14 => UCharCategory::U_PARAGRAPH_SEPARATOR,
101            15 => UCharCategory::U_CONTROL_CHAR,
102            16 => UCharCategory::U_FORMAT_CHAR,
103            17 => UCharCategory::U_PRIVATE_USE_CHAR,
104            18 => UCharCategory::U_SURROGATE,
105            19 => UCharCategory::U_DASH_PUNCTUATION,
106            20 => UCharCategory::U_START_PUNCTUATION,
107            21 => UCharCategory::U_END_PUNCTUATION,
108            22 => UCharCategory::U_CONNECTOR_PUNCTUATION,
109            23 => UCharCategory::U_OTHER_PUNCTUATION,
110            24 => UCharCategory::U_MATH_SYMBOL,
111            25 => UCharCategory::U_CURRENCY_SYMBOL,
112            26 => UCharCategory::U_MODIFIER_SYMBOL,
113            27 => UCharCategory::U_OTHER_SYMBOL,
114            28 => UCharCategory::U_INITIAL_PUNCTUATION,
115            29 => UCharCategory::U_FINAL_PUNCTUATION,
116            30 => UCharCategory::U_CHAR_CATEGORY_COUNT,
117            _ => {
118                panic!("could not convert: {}", value);
119            }
120        }
121    }
122}
123
124// Items used by the `versioned_function!` macro. Unstable private API; do not use.
125#[doc(hidden)]
126pub mod __private_do_not_use {
127    pub extern crate paste;
128}