socketry_markdown/
message.rs1use crate::unist::{Point, Position};
6use alloc::{boxed::Box, fmt, string::String};
7
8#[derive(Clone, Debug, PartialEq)]
9pub struct Message {
10 pub place: Option<Box<Place>>,
12 pub reason: String,
14 pub rule_id: Box<String>,
16 pub source: Box<String>,
18}
19
20impl fmt::Display for Message {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 if let Some(ref place) = self.place {
23 write!(f, "{place}: ")?;
24 }
25
26 write!(f, "{} ({}:{})", self.reason, self.source, self.rule_id)
27 }
28}
29
30#[derive(Clone, Debug, PartialEq)]
32pub enum Place {
33 Position(Position),
35 Point(Point),
37}
38
39impl fmt::Display for Place {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Place::Position(position) => write!(
43 f,
44 "{}:{}-{}:{}",
45 position.start.line, position.start.column, position.end.line, position.end.column
46 ),
47 Place::Point(point) => write!(f, "{}:{}", point.line, point.column),
48 }
49 }
50}