Skip to main content

model_core/
value.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Open-ended facts a frontend or an analysis attaches to an entity
6/// (annotations, modifiers, visibility, HTTP endpoints...). Keys are
7/// namespaced by convention: `java.annotations`, `http.endpoints`.
8pub type Props = BTreeMap<String, Value>;
9
10/// Number of cyclomatic decision points extracted from an entity's syntax
11/// (`if`, loops, `catch`, logical operators...). A frontend fact, not a
12/// derived metric: `model-analysis` computes cyclomatic complexity from it.
13pub const BRANCHES_PROP: &str = "complexity.branches";
14
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16#[serde(untagged)]
17pub enum Value {
18    Bool(bool),
19    Int(i64),
20    Str(String),
21    List(Vec<Value>),
22    Map(BTreeMap<String, Value>),
23}
24
25impl From<bool> for Value {
26    fn from(v: bool) -> Self {
27        Value::Bool(v)
28    }
29}
30
31impl From<i64> for Value {
32    fn from(v: i64) -> Self {
33        Value::Int(v)
34    }
35}
36
37impl From<&str> for Value {
38    fn from(v: &str) -> Self {
39        Value::Str(v.to_string())
40    }
41}
42
43impl From<String> for Value {
44    fn from(v: String) -> Self {
45        Value::Str(v)
46    }
47}
48
49impl<T: Into<Value>> From<Vec<T>> for Value {
50    fn from(v: Vec<T>) -> Self {
51        Value::List(v.into_iter().map(Into::into).collect())
52    }
53}