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

divviup / divviup-api / 30497640873

29 Jul 2026 10:52PM UTC coverage: 69.172% (+0.01%) from 69.161%
30497640873

Pull #2406

github

web-flow
Merge a48726d2f into b314d9827
Pull Request #2406: Bump sea-orm from 1.1.20 to 2.0.0

8 of 9 new or added lines in 4 files covered. (88.89%)

1 existing line in 1 file now uncovered.

4501 of 6507 relevant lines covered (69.17%)

69.92 hits per line

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

52.08
/src/entity/codec.rs
1
use janus_messages::codec::{Decode, Encode};
2
use prio::codec::CodecError;
3
use sea_orm::{
4
    entity::ColumnType,
5
    sea_query::{ArrayType, Nullable, ValueType, ValueTypeErr},
6
    ColIdx, DbErr, QueryResult, TryGetError, TryGetable, Value,
7
};
8
use serde::{Deserialize, Serialize};
9
use std::{
10
    any::type_name,
11
    fmt::{self, Debug, Display, Formatter},
12
    ops::{Deref, DerefMut},
13
};
14

15
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, Default)]
16
pub struct Codec<T>(T);
17

18
impl<T: Display> Display for Codec<T> {
19
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
×
20
        self.0.fmt(f)
×
21
    }
×
22
}
23
impl<T: PartialEq> PartialEq<T> for Codec<T> {
24
    fn eq(&self, other: &T) -> bool {
1✔
25
        &self.0 == other
1✔
26
    }
1✔
27
}
28
impl<T> Deref for Codec<T> {
29
    type Target = T;
30

31
    fn deref(&self) -> &Self::Target {
14✔
32
        &self.0
14✔
33
    }
14✔
34
}
35
impl<T> DerefMut for Codec<T> {
36
    fn deref_mut(&mut self) -> &mut Self::Target {
×
37
        &mut self.0
×
38
    }
×
39
}
40

41
impl<T: Encode + Decode> From<Codec<T>> for Value {
42
    fn from(value: Codec<T>) -> Self {
108✔
43
        // Unwrap safety: this type cannot be constructed without validating that it's encodeable.
44
        //
45
        // Ideally we'd do an `impl TryFrom` on this type, but that is insufficient to satisfy the
46
        // type constraints for a type deriving DeriveEntityModel.
47
        Value::Bytes(Some(value.0.get_encoded().unwrap()))
108✔
48
    }
108✔
49
}
50

51
impl<T: Encode + Decode> Codec<T> {
52
    pub fn new(value: T) -> Result<Self, CodecError> {
98✔
53
        value.get_encoded()?;
98✔
54
        Ok(Self(value))
98✔
55
    }
98✔
56
}
57

58
impl<T> Codec<T> {
59
    pub fn into_inner(self) -> T {
×
60
        self.0
×
61
    }
×
62
}
63

64
impl<T: Encode + Decode> TryGetable for Codec<T> {
65
    fn try_get_by<I: ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> {
159✔
66
        match res
159✔
67
            .try_get_by::<Vec<u8>, _>(idx)
159✔
68
            .map_err(TryGetError::DbErr)?
159✔
69
        {
70
            empty if empty.is_empty() => Err(TryGetError::Null(format!("{idx:?}"))),
159✔
71
            bytes => T::get_decoded(&bytes)
159✔
72
                .map(Codec)
159✔
73
                .map_err(|e| TryGetError::DbErr(DbErr::Custom(e.to_string()))),
159✔
74
        }
75
    }
159✔
76
}
77

78
impl<T: Encode + Decode> ValueType for Codec<T> {
79
    fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
×
80
        match v {
×
81
            Value::Bytes(Some(x)) => T::get_decoded(&x).map(Codec).map_err(|_| ValueTypeErr),
×
82
            _ => Err(ValueTypeErr),
×
83
        }
84
    }
×
85

86
    fn type_name() -> String {
×
87
        type_name::<T>().to_string()
×
88
    }
×
89

90
    fn array_type() -> ArrayType {
×
91
        ArrayType::Bytes
×
92
    }
×
93

94
    fn column_type() -> ColumnType {
538✔
95
        ColumnType::Blob
538✔
96
    }
538✔
97
}
98

99
impl<T: Encode + Decode> Nullable for Codec<T> {
100
    fn null() -> Value {
×
NEW
101
        Value::Bytes(Some(Vec::default()))
×
102
    }
×
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc