pleiades_data/coverage/
body.rs1use super::*;
2
3#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct PackagedBodyCoverageSummary {
6 pub body_count: usize,
8 pub bodies: Vec<CelestialBody>,
10}
11
12#[derive(Clone, Debug, Eq, PartialEq)]
14pub enum PackagedBodyCoverageSummaryValidationError {
15 FieldOutOfSync { field: &'static str },
17}
18
19impl fmt::Display for PackagedBodyCoverageSummaryValidationError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Self::FieldOutOfSync { field } => write!(
23 f,
24 "the packaged body coverage summary field `{field}` is out of sync with the current bundled body set"
25 ),
26 }
27 }
28}
29
30impl std::error::Error for PackagedBodyCoverageSummaryValidationError {}
31
32impl PackagedBodyCoverageSummary {
33 pub fn summary_line(&self) -> String {
35 format!(
36 "Packaged body set: {} bundled bodies ({})",
37 self.body_count,
38 join_display(&self.bodies)
39 )
40 }
41
42 pub fn validate(&self) -> Result<(), PackagedBodyCoverageSummaryValidationError> {
44 let expected_bodies = packaged_bodies();
45
46 if self.body_count != expected_bodies.len() {
47 return Err(PackagedBodyCoverageSummaryValidationError::FieldOutOfSync {
48 field: "body_count",
49 });
50 }
51 if self.bodies.as_slice() != expected_bodies {
52 return Err(PackagedBodyCoverageSummaryValidationError::FieldOutOfSync {
53 field: "bodies",
54 });
55 }
56
57 Ok(())
58 }
59
60 pub fn validated_summary_line(
62 &self,
63 ) -> Result<String, PackagedBodyCoverageSummaryValidationError> {
64 self.validate()?;
65 Ok(self.summary_line())
66 }
67}
68
69impl fmt::Display for PackagedBodyCoverageSummary {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 f.write_str(&self.summary_line())
72 }
73}
74
75pub fn packaged_body_coverage_summary_details() -> PackagedBodyCoverageSummary {
77 let bodies = packaged_bodies().to_vec();
78 PackagedBodyCoverageSummary {
79 body_count: bodies.len(),
80 bodies,
81 }
82}