Skip to main content

rdf_model/
any_statement.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::{
4    AnyTerm, CowTerm, EMPTY_COW_QUAD_PATTERN, EMPTY_HEAP_QUAD_PATTERN, HeapTerm, QuadPattern,
5    Statement, StatementPattern, Term,
6};
7use core::{borrow::Borrow, marker::PhantomData};
8
9pub type AnyQuad = AnyStatement;
10pub type AnyTriple = AnyStatement;
11
12#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
13pub struct AnyStatement;
14
15impl StatementPattern for AnyStatement {
16    type Term = AnyTerm;
17
18    fn matches(&self, _: impl Term, _: impl Term, _: impl Term, _: Option<impl Term>) -> bool {
19        true
20    }
21}
22
23#[cfg(feature = "alloc")]
24impl From<AnyStatement> for crate::CowTriplePattern<'_> {
25    fn from(_: AnyStatement) -> Self {
26        Self::empty()
27    }
28}
29
30#[cfg(feature = "alloc")]
31impl From<AnyStatement> for crate::CowQuadPattern<'_> {
32    fn from(_: AnyStatement) -> Self {
33        Self::empty()
34    }
35}
36
37#[cfg(feature = "alloc")]
38impl From<AnyStatement> for crate::HeapTriplePattern {
39    fn from(_: AnyStatement) -> Self {
40        Self::empty()
41    }
42}
43
44#[cfg(feature = "alloc")]
45impl From<AnyStatement> for crate::HeapQuadPattern {
46    fn from(_: AnyStatement) -> Self {
47        Self::empty()
48    }
49}
50
51#[cfg(feature = "alloc")]
52impl TryFrom<crate::CowTriplePattern<'_>> for AnyStatement {
53    type Error = ();
54
55    fn try_from(input: crate::CowTriplePattern<'_>) -> Result<Self, Self::Error> {
56        if input.is_empty() {
57            Ok(Self::default())
58        } else {
59            Err(())
60        }
61    }
62}
63
64#[cfg(feature = "alloc")]
65impl TryFrom<crate::CowQuadPattern<'_>> for AnyStatement {
66    type Error = ();
67
68    fn try_from(input: crate::CowQuadPattern<'_>) -> Result<Self, Self::Error> {
69        if input.is_empty() {
70            Ok(Self::default())
71        } else {
72            Err(())
73        }
74    }
75}
76
77#[cfg(feature = "alloc")]
78impl TryFrom<crate::HeapTriplePattern> for AnyStatement {
79    type Error = ();
80
81    fn try_from(input: crate::HeapTriplePattern) -> Result<Self, Self::Error> {
82        if input.is_empty() {
83            Ok(Self::default())
84        } else {
85            Err(())
86        }
87    }
88}
89
90#[cfg(feature = "alloc")]
91impl TryFrom<crate::HeapQuadPattern> for AnyStatement {
92    type Error = ();
93
94    fn try_from(input: crate::HeapQuadPattern) -> Result<Self, Self::Error> {
95        if input.is_empty() {
96            Ok(Self::default())
97        } else {
98            Err(())
99        }
100    }
101}
102
103impl Borrow<QuadPattern<CowTerm<'static>>> for AnyStatement {
104    fn borrow(&self) -> &QuadPattern<CowTerm<'static>> {
105        &EMPTY_COW_QUAD_PATTERN
106    }
107}
108
109impl Borrow<QuadPattern<HeapTerm>> for AnyStatement {
110    fn borrow(&self) -> &QuadPattern<HeapTerm> {
111        &EMPTY_HEAP_QUAD_PATTERN
112    }
113}