obs_types/lib.rs
1#![forbid(unsafe_code)]
2#![warn(rust_2024_compatibility, missing_docs, missing_debug_implementations)]
3// Tests routinely use `.unwrap()` for clarity; production code uses `?`.
4#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
5
6//! Foundation enums for the obs SDK.
7//!
8//! Every other crate in the workspace depends on this one. The seven enums
9//! defined here form the vocabulary of the wire envelope ([10-data-model.md
10//! § 2-5](../../specs/10-data-model.md)) — `Tier`, `Severity`, `FieldKind`,
11//! `Cardinality`, `Classification`, `MetricKind`, `SamplingReason`.
12//!
13//! All enums:
14//! - derive `Copy + Clone + Debug + PartialEq + Eq + Hash`,
15//! - implement [`buffa::Enumeration`] so they live on the wire,
16//! - serialize/deserialize via `serde` for `obs.yaml` config,
17//! - expose `const fn` helpers used by compile-time lints (e.g.
18//! [`Cardinality::is_label_compatible`], [`Cardinality::cap`], [`Severity::as_str`]).
19//!
20//! Vocabulary changes here cause an envelope `format_ver` bump (per
21//! [10-data-model.md § 6](../../specs/10-data-model.md#6-envelope) and
22//! [61-crates-and-features.md § 4](../../specs/61-crates-and-features.md#4-versioning-policy)).
23//! That's the intended forcing function.
24
25mod cardinality;
26mod classification;
27mod field_kind;
28mod metric_kind;
29mod sampling;
30mod severity;
31mod tier;
32
33pub use cardinality::Cardinality;
34pub use classification::Classification;
35pub use field_kind::FieldKind;
36pub use metric_kind::MetricKind;
37pub use sampling::SamplingReason;
38pub use severity::Severity;
39pub use tier::Tier;
40
41/// Error returned by `TryFrom<&str>` and `FromStr` parsers when an unknown
42/// enum name is encountered. Each enum in this crate uses this type to
43/// preserve a uniform error surface across the vocabulary.
44#[derive(Debug, thiserror::Error)]
45#[error("unknown {kind} variant: {value:?}")]
46pub struct UnknownVariant {
47 /// The enum name (e.g. `"Severity"`).
48 pub kind: &'static str,
49 /// The unrecognised input.
50 pub value: String,
51}