#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
// TODO(#2266): enable missing_debug_implementations,
)
)]
#![allow(clippy::panic)]
#![allow(clippy::expect_used)]
use icu_collections::codepointtrie::toml::CodePointTrieToml;
use icu_collections::codepointtrie::CodePointTrie;
use icu_collections::codepointtrie::TrieType;
use icu_collections::codepointtrie::TrieValue;
use std::convert::TryInto;
mod wasm;
#[non_exhaustive]
pub enum CodePointTrieBuilderData<'a, T> {
ValuesByCodePoint(&'a [T]),
}
#[allow(clippy::exhaustive_structs)]
pub struct CodePointTrieBuilder<'a, T> {
pub data: CodePointTrieBuilderData<'a, T>,
pub default_value: T,
pub error_value: T,
pub trie_type: TrieType,
}
impl<T> CodePointTrieBuilder<'_, T>
where
T: TrieValue + Into<u32>,
{
pub fn build(self) -> CodePointTrie<'static, T> {
let toml_str = wasm::run_wasm(&self);
let toml_obj: CodePointTrieToml =
toml::from_str(&toml_str).expect("the tool should produce valid TOML");
(&toml_obj)
.try_into()
.expect("the toml should be a valid CPT")
}
}