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

divviup / divviup-api / 13234376066

10 Feb 2025 05:43AM UTC coverage: 55.709% (+0.04%) from 55.666%
13234376066

Pull #1560

github

web-flow
Merge 8925d9cb3 into 96076b4d9
Pull Request #1560: Bump janus_messages from 0.7.49 to 0.7.50 in the janus group

3879 of 6963 relevant lines covered (55.71%)

85.86 hits per line

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

73.91
/src/entity/aggregator/role.rs
1
use rand::{distributions::Standard, prelude::Distribution};
2
use sea_orm::{DeriveActiveEnum, EnumIter};
3
use serde::{Deserialize, Serialize};
4
use std::{
5
    error::Error,
6
    fmt::{self, Display, Formatter},
7
    str::FromStr,
8
};
9

10
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
×
11
#[sea_orm(rs_type = "i32", db_type = "Integer")]
12
pub enum Role {
13
    #[sea_orm(num_value = 0)]
14
    Leader,
15
    #[sea_orm(num_value = 1)]
16
    Helper,
17
    #[sea_orm(num_value = 2)]
18
    Either,
19
}
20

21
impl Distribution<Role> for Standard {
22
    fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Role {
22✔
23
        match rng.gen_range(0..3) {
22✔
24
            0 => Role::Leader,
7✔
25
            1 => Role::Helper,
10✔
26
            _ => Role::Either,
5✔
27
        }
28
    }
22✔
29
}
30
impl AsRef<str> for Role {
31
    fn as_ref(&self) -> &str {
2✔
32
        match self {
2✔
33
            Self::Leader => "leader",
×
34
            Self::Helper => "helper",
1✔
35
            Self::Either => "either",
1✔
36
        }
37
    }
2✔
38
}
39

40
#[derive(Debug)]
41
pub struct UnrecognizedRole(String);
42
impl Display for UnrecognizedRole {
43
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
×
44
        f.write_fmt(format_args!("{} was not a recognized role option", self.0))
×
45
    }
×
46
}
47
impl Error for UnrecognizedRole {}
48
impl FromStr for Role {
49
    type Err = UnrecognizedRole;
50
    fn from_str(s: &str) -> Result<Self, Self::Err> {
2✔
51
        match &*s.to_lowercase() {
2✔
52
            "leader" => Ok(Self::Leader),
2✔
53
            "helper" => Ok(Self::Helper),
2✔
54
            "either" => Ok(Self::Either),
1✔
55
            unrecognized => Err(UnrecognizedRole(unrecognized.to_string())),
×
56
        }
57
    }
2✔
58
}
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