1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::fmt::Display;
use thiserror::Error;
pub(crate) const FEATURE_REQUEST_URL: &str =
"https://github.com/V0ldek/rsonpath/issues/new?template=feature_request.md";
pub(crate) const BUG_REPORT_URL: &str =
"https://github.com/V0ldek/rsonpath/issues/new?template=bug_report.md";
#[derive(Error, Debug)]
pub struct UnsupportedFeatureError {
issue: Option<usize>,
feature: &'static str,
}
impl UnsupportedFeatureError {
#[must_use]
#[allow(dead_code)]
#[inline(always)]
fn tracked(issue: usize, feature: &'static str) -> Self {
Self {
issue: Some(issue),
feature,
}
}
#[must_use]
#[inline(always)]
fn untracked(feature: &'static str) -> Self {
Self {
issue: None,
feature,
}
}
#[must_use]
#[inline(always)]
pub fn large_json_depths() -> Self {
Self::untracked("Large JSON Depths")
}
#[must_use]
#[inline(always)]
pub fn large_automaton_queries() -> Self {
Self::untracked("Large Automaton Queries")
}
#[must_use]
#[inline(always)]
pub fn issue(&self) -> Option<usize> {
self.issue
}
#[must_use]
#[inline(always)]
pub fn feature(&self) -> &str {
self.feature
}
#[must_use]
#[inline(always)]
pub fn is_planned(&self) -> bool {
self.issue.is_some()
}
}
impl Display for UnsupportedFeatureError {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.issue {
Some(issue) => {
write!(
f,
"the feature {} (#{}) is not supported yet; it is being tracked and discussed at \
https://github.com/V0ldek/rsonpath/issues/{}",
self.feature, issue, issue
)
}
None => {
write!(
f,
"the feature {} is not supported, and is not planned; \
if you would like to see it introduced to rsonpath, please raise a feature request at \
{FEATURE_REQUEST_URL}",
self.feature
)
}
}
}
}