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 ).
45use displaydoc::Display;
67/// Error types for the `zerotrie` crate.
8#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ZeroTrieBuildError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ZeroTrieBuildError::NonAsciiError => "NonAsciiError",
ZeroTrieBuildError::CapacityExceeded => "CapacityExceeded",
ZeroTrieBuildError::CouldNotSolvePerfectHash =>
"CouldNotSolvePerfectHash",
ZeroTrieBuildError::MixedCase => "MixedCase",
ZeroTrieBuildError::IllegalDelimiter => "IllegalDelimiter",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ZeroTrieBuildError { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ZeroTrieBuildError {
#[inline]
fn clone(&self) -> ZeroTrieBuildError { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ZeroTrieBuildError {
#[inline]
fn eq(&self, other: &ZeroTrieBuildError) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ZeroTrieBuildError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const _: () =
{
impl ::core::fmt::Display for ZeroTrieBuildError {
fn fmt(&self, formatter: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
#[allow(unused_variables)]
match self {
Self::NonAsciiError => {
formatter.write_fmt(format_args!("Non-ASCII cannot be added to an ASCII-only trie"))
}
Self::CapacityExceeded => {
formatter.write_fmt(format_args!("Reached maximum capacity of trie"))
}
Self::CouldNotSolvePerfectHash => {
formatter.write_fmt(format_args!("Failed to solve the perfect hash function. This is rare! Please report your case to the ICU4X team."))
}
Self::MixedCase => {
formatter.write_fmt(format_args!("Mixed-case data added to case-insensitive trie"))
}
Self::IllegalDelimiter => {
formatter.write_fmt(format_args!("Delimiter is contained in one or more strings"))
}
}
}
}
};Display)]
9#[non_exhaustive]
10pub enum ZeroTrieBuildError {
11/// Non-ASCII data was added to an ASCII-only trie.
12#[displaydoc("Non-ASCII cannot be added to an ASCII-only trie")]
13NonAsciiError,
14/// The trie reached its maximum supported capacity.
15#[displaydoc("Reached maximum capacity of trie")]
16CapacityExceeded,
17/// The builder could not solve the perfect hash function.
18#[displaydoc("Failed to solve the perfect hash function. This is rare! Please report your case to the ICU4X team.")]
19CouldNotSolvePerfectHash,
20/// Mixed-case data was added to a case-insensitive trie.
21#[displaydoc("Mixed-case data added to case-insensitive trie")]
22MixedCase,
23/// Strings were added to a trie containing the delimiter.
24 ///
25 /// # Examples
26 ///
27 /// ```
28 /// use std::collections::BTreeMap;
29 /// use zerotrie::dense::ZeroAsciiDenseSparse2dTrieOwned;
30 /// use zerotrie::ZeroTrieBuildError;
31 ///
32 /// let mut data: BTreeMap<&str, BTreeMap<&str, usize>> = BTreeMap::new();
33 ///
34 /// // Delimiter in a prefix
35 /// data.entry("aa/bb").or_default().insert("CCC", 1);
36 /// let err =
37 /// ZeroAsciiDenseSparse2dTrieOwned::try_from_btree_map_str(&data, b'/')
38 /// .unwrap_err();
39 /// assert_eq!(err, ZeroTrieBuildError::IllegalDelimiter);
40 ///
41 /// // Delimiter in a suffix
42 /// data.clear();
43 /// data.entry("aaa").or_default().insert("BB/CC", 1);
44 /// let err =
45 /// ZeroAsciiDenseSparse2dTrieOwned::try_from_btree_map_str(&data, b'/')
46 /// .unwrap_err();
47 /// assert_eq!(err, ZeroTrieBuildError::IllegalDelimiter);
48 /// ```
49#[displaydoc("Delimiter is contained in one or more strings")]
50IllegalDelimiter,
51}
5253impl core::error::Errorfor ZeroTrieBuildError {}