• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zbraniecki / icu4x / 6815798908

09 Nov 2023 05:17PM UTC coverage: 72.607% (-2.4%) from 75.01%
6815798908

push

github

web-flow
Implement `Any/BufferProvider` for some smart pointers (#4255)

Allows storing them as a `Box<dyn Any/BufferProvider>` without using a
wrapper type that implements the trait.

44281 of 60987 relevant lines covered (72.61%)

201375.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.19
/components/collections/src/codepointtrie/serde.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
use crate::codepointtrie::{CodePointTrie, CodePointTrieHeader, TrieValue};
6
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
7
use zerofrom::ZeroFrom;
8
use zerovec::ZeroVec;
9

10
#[derive(Serialize, Deserialize)]
3✔
11
pub struct CodePointTrieSerde<'trie, T: TrieValue> {
12
    header: CodePointTrieHeader,
13
    #[serde(borrow)]
14
    index: ZeroVec<'trie, u16>,
15
    #[serde(borrow)]
16
    data: ZeroVec<'trie, T>,
17
}
18

19
impl<'trie, T: TrieValue + Serialize> Serialize for CodePointTrie<'trie, T> {
20
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1✔
21
    where
22
        S: Serializer,
23
    {
24
        let ser = CodePointTrieSerde {
2✔
25
            header: self.header,
1✔
26
            index: ZeroFrom::zero_from(&self.index),
1✔
27
            data: ZeroFrom::zero_from(&self.data),
1✔
28
        };
×
29
        ser.serialize(serializer)
1✔
30
    }
1✔
31
}
32

33
impl<'de, 'trie, T: TrieValue + Deserialize<'de>> Deserialize<'de> for CodePointTrie<'trie, T>
34
where
35
    'de: 'trie,
36
{
37
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1✔
38
    where
39
        D: Deserializer<'de>,
40
    {
41
        let de = CodePointTrieSerde::deserialize(deserializer)?;
1✔
42
        let error_value = de.data.last().ok_or_else(|| {
1✔
43
            D::Error::custom("CodePointTrie vector must have at least one element")
×
44
        })?;
×
45
        Ok(CodePointTrie {
1✔
46
            header: de.header,
1✔
47
            index: de.index,
1✔
48
            data: de.data,
1✔
49
            error_value,
×
50
        })
51
    }
1✔
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc