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

divviup / divviup-api / 12229392494

09 Dec 2024 05:13AM UTC coverage: 56.117% (-0.04%) from 56.159%
12229392494

Pull #1436

github

web-flow
Merge 1e59d8ad3 into fedf4d7b3
Pull Request #1436: Bump react-router from 6.28.0 to 7.0.2 in /app

3945 of 7030 relevant lines covered (56.12%)

96.01 hits per line

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

65.22
/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)]
140✔
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,
8✔
25
            1 => Role::Helper,
8✔
26
            _ => Role::Either,
6✔
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",
2✔
34
            Self::Helper => "helper",
×
35
            Self::Either => "either",
×
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),
×
54
            "either" => Ok(Self::Either),
×
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