diff --git a/provider/uprops/src/enum_codepointtrie.rs b/provider/uprops/src/enum_codepointtrie.rs index 44e82d30fcd..7b582665fd5 100644 --- a/provider/uprops/src/enum_codepointtrie.rs +++ b/provider/uprops/src/enum_codepointtrie.rs @@ -52,14 +52,27 @@ impl TryFrom = ZeroVec::from_slice(&cpt_data.index); + let index: ZeroVec = ZeroVec::clone_from_slice(&cpt_data.index); // TODO: make data have type ZeroVec - let data = if let Some(data_8) = cpt_data.data_8 { - ZeroVec::from_slice(data_8.as_slice()) + // + let data: Result, String> = if let Some(data_8) = cpt_data.data_8 { + data_8 + .iter() + .map(|i| *i as u32) + .map(|i| T::parse_from_u32(i).map(|i| i.as_unaligned())) + .collect() } else if let Some(data_16) = cpt_data.data_16 { - ZeroVec::from_slice(data_16.as_slice()) + data_16 + .iter() + .map(|i| *i as u32) + .map(|i| T::parse_from_u32(i).map(|i| i.as_unaligned())) + .collect() } else if let Some(data_32) = cpt_data.data_32 { - ZeroVec::from_slice(data_32.as_slice()) + data_32 + .iter() + .map(|i| *i as u32) + .map(|i| T::parse_from_u32(i).map(|i| i.as_unaligned())) + .collect() } else { return Err(DataError::new_resc_error( icu_codepointtrie::error::Error::FromDeserialized { @@ -67,8 +80,10 @@ impl TryFrom::try_new(header, index, data).map_err(DataError::new_resc_error); + + let data = ZeroVec::Owned(data.map_err(DataError::new_resc_error)?); + let trie = CodePointTrie::::try_new(header, index, data) + .map_err(DataError::new_resc_error); trie.map(|t| UnicodePropertyMapV1 { codepoint_trie: t }) } } diff --git a/utils/codepointtrie/src/codepointtrie.rs b/utils/codepointtrie/src/codepointtrie.rs index 10144daf2d8..db586ebca19 100644 --- a/utils/codepointtrie/src/codepointtrie.rs +++ b/utils/codepointtrie/src/codepointtrie.rs @@ -5,7 +5,7 @@ use crate::error::Error; use crate::impl_const::*; -use core::convert::TryFrom; +use core::convert::{TryFrom, TryInto}; use icu_provider::yoke::ZeroCopyFrom; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -33,18 +33,28 @@ pub enum TrieType { /// This trait is used as a type parameter in constructing a `CodePointTrie`. pub trait TrieValue: Copy + zerovec::ule::AsULE + 'static { const DATA_GET_ERROR_VALUE: Self; + fn parse_from_u32(i: u32) -> Result; } impl TrieValue for u8 { const DATA_GET_ERROR_VALUE: u8 = u8::MAX; + fn parse_from_u32(i: u32) -> Result { + Self::try_from(i).map_err(|e| e.to_string()) + } } impl TrieValue for u16 { const DATA_GET_ERROR_VALUE: u16 = u16::MAX; + fn parse_from_u32(i: u32) -> Result { + Self::try_from(i).map_err(|e| e.to_string()) + } } impl TrieValue for u32 { const DATA_GET_ERROR_VALUE: u32 = u32::MAX; + fn parse_from_u32(i: u32) -> Result { + Self::try_from(i).map_err(|e| e.to_string()) + } } /// This struct represents a de-serialized CodePointTrie that was exported from