prometheus_wire/parser/
comment.rs

1/// If it is a `type` or `help` comment.
2/// More details: [comments, help text, and type information](https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information).
3#[derive(Debug, PartialEq)]
4pub enum CommentType {
5    TYPE,
6    HELP,
7    UNKNOWN,
8}
9
10/// Represents parsed `type` or `help` comments for each `metric`. See examples at [try_read_comment](super::try_read_comment) for more details.
11#[derive(Debug, PartialEq)]
12pub struct Comment {
13    pub metric: String,
14    pub comment_type: CommentType,
15    pub description: String,
16}
17
18impl From<&str> for CommentType {
19    fn from(s: &str) -> Self {
20        match s {
21            "TYPE" => CommentType::TYPE,
22            "HELP" => CommentType::HELP,
23            _ => CommentType::UNKNOWN,
24        }
25    }
26}
27
28impl Comment {
29    pub fn new(metric: String, comment_type: CommentType, desc: String) -> Self {
30        Comment {
31            metric,
32            comment_type,
33            description: desc,
34        }
35    }
36}