mod builder;
use crate::{files::FileId, label::Label, note::Note, severity::Severity};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Message<Id: FileId> {
pub(crate) text: String,
pub(crate) identifier: Option<Identifier>,
pub(crate) severity: Option<Severity>,
pub(crate) labels: Vec<Label<Id>>,
pub(crate) notes: Vec<Note>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Identifier {
Simple(String),
Hyperlink(String, String),
}
impl Identifier {
#[must_use]
pub const fn simple(text: String) -> Self {
Self::Simple(text)
}
#[must_use]
pub const fn hyperlink(text: String, url: String) -> Self {
Self::Hyperlink(text, url)
}
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::Hyperlink(text, _) | Self::Simple(text) => text,
}
}
#[must_use]
pub fn len(&self) -> usize {
self.as_str().len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.as_str().is_empty()
}
#[must_use]
pub const fn is_hyperlink(&self) -> bool {
matches!(self, Self::Hyperlink(_, _))
}
#[must_use]
pub fn url(&self) -> Option<&str> {
match self {
Self::Hyperlink(_, url) => Some(url),
Self::Simple(_) => None,
}
}
}