json_ld_expansion_next/
warning.rs

1use contextual::DisplayWithContext;
2use json_ld_context_processing_next::algorithm::MalformedIri;
3use langtag::InvalidLangTag;
4use rdf_types::vocabulary::BlankIdVocabulary;
5use std::fmt;
6
7#[derive(Debug)]
8pub enum Warning<B> {
9	MalformedIri(String),
10	EmptyTerm,
11	BlankNodeIdProperty(B),
12	MalformedLanguageTag(String, InvalidLangTag<String>),
13}
14
15impl<B> From<MalformedIri> for Warning<B> {
16	fn from(MalformedIri(s): MalformedIri) -> Self {
17		Self::MalformedIri(s)
18	}
19}
20
21impl<B: fmt::Display> fmt::Display for Warning<B> {
22	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23		match self {
24			Self::MalformedIri(s) => write!(f, "malformed IRI `{s}`"),
25			Self::EmptyTerm => write!(f, "empty term"),
26			Self::BlankNodeIdProperty(b) => {
27				write!(f, "blank node identifier `{b}` used as property")
28			}
29			Self::MalformedLanguageTag(t, e) => write!(f, "invalid language tag `{t}`: {e}"),
30		}
31	}
32}
33
34impl<B, N: BlankIdVocabulary<BlankId = B>> DisplayWithContext<N> for Warning<B> {
35	fn fmt_with(&self, vocabulary: &N, f: &mut fmt::Formatter) -> fmt::Result {
36		match self {
37			Self::MalformedIri(s) => write!(f, "malformed IRI `{s}`"),
38			Self::EmptyTerm => write!(f, "empty term"),
39			Self::BlankNodeIdProperty(b) => {
40				write!(
41					f,
42					"blank node identifier `{}` used as property",
43					vocabulary.blank_id(b).unwrap()
44				)
45			}
46			Self::MalformedLanguageTag(t, e) => write!(f, "invalid language tag `{t}`: {e}"),
47		}
48	}
49}