graphrecords_query/error/
ordering.rs1use crate::{Diagnostic, OwnedIndex};
2use std::{
3 error::Error,
4 fmt::{self, Debug, Display, Formatter},
5};
6
7#[derive(Debug)]
8pub struct IncomparableIndices<V, E: OwnedIndex> {
9 value: V,
10 first: E,
11 second: E,
12}
13
14impl<V, E: OwnedIndex> IncomparableIndices<V, E> {
15 #[must_use]
16 pub const fn new(value: V, first: E, second: E) -> Self {
17 Self {
18 value,
19 first,
20 second,
21 }
22 }
23
24 #[must_use]
25 pub const fn value(&self) -> &V {
26 &self.value
27 }
28
29 #[must_use]
30 pub const fn first(&self) -> &E {
31 &self.first
32 }
33
34 #[must_use]
35 pub const fn second(&self) -> &E {
36 &self.second
37 }
38}
39
40impl<V: Display, E: OwnedIndex> Display for IncomparableIndices<V, E> {
41 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
42 write!(
43 formatter,
44 "cannot order elements sharing value `{}`: their indices `{}` and `{}` are not comparable",
45 self.value, self.first, self.second
46 )
47 }
48}
49
50impl<V: Debug + Display, E: OwnedIndex> Error for IncomparableIndices<V, E> {}
51
52impl<V: Debug + Display + Send + Sync + 'static, E: OwnedIndex> Diagnostic
53 for IncomparableIndices<V, E>
54{
55 fn name() -> &'static str {
56 "IncomparableIndices"
57 }
58
59 fn help(&self) -> Option<String> {
60 Some(
61 "to order them deterministically, sort by a key that distinguishes these elements"
62 .to_string(),
63 )
64 }
65}