json_ld_context_processing/
processed.rs

1use iref::IriBuf;
2use json_ld_core::Context;
3use rdf_types::BlankIdBuf;
4use std::ops;
5
6/// Processed context that also borrows the original, unprocessed, context.
7pub struct Processed<'l, T = IriBuf, B = BlankIdBuf> {
8	pub unprocessed: &'l json_ld_syntax::context::Context,
9	pub processed: Context<T, B>,
10}
11
12impl<'l, T, B> Processed<'l, T, B> {
13	pub fn new(
14		unprocessed: &'l json_ld_syntax::context::Context,
15		processed: Context<T, B>,
16	) -> Self {
17		Self {
18			unprocessed,
19			processed,
20		}
21	}
22
23	pub fn unprocessed(&self) -> &'l json_ld_syntax::context::Context {
24		self.unprocessed
25	}
26
27	pub fn into_processed(self) -> Context<T, B> {
28		self.processed
29	}
30
31	pub fn as_ref(&self) -> ProcessedRef<'l, '_, T, B> {
32		ProcessedRef {
33			unprocessed: self.unprocessed,
34			processed: &self.processed,
35		}
36	}
37
38	pub fn into_owned(self) -> ProcessedOwned<T, B> {
39		ProcessedOwned {
40			unprocessed: self.unprocessed.clone(),
41			processed: self.processed,
42		}
43	}
44}
45
46impl<'l, T, B> ops::Deref for Processed<'l, T, B> {
47	type Target = Context<T, B>;
48
49	fn deref(&self) -> &Self::Target {
50		&self.processed
51	}
52}
53
54impl<'l, T, B> ops::DerefMut for Processed<'l, T, B> {
55	fn deref_mut(&mut self) -> &mut Self::Target {
56		&mut self.processed
57	}
58}
59
60/// Reference to a processed context that also borrows the original, unprocessed, context.
61pub struct ProcessedRef<'l, 'a, T, B> {
62	pub unprocessed: &'l json_ld_syntax::context::Context,
63	pub processed: &'a Context<T, B>,
64}
65
66impl<'l, 'a, T, B> ProcessedRef<'l, 'a, T, B> {
67	pub fn new(
68		unprocessed: &'l json_ld_syntax::context::Context,
69		processed: &'a Context<T, B>,
70	) -> Self {
71		Self {
72			unprocessed,
73			processed,
74		}
75	}
76
77	pub fn unprocessed(&self) -> &'l json_ld_syntax::context::Context {
78		self.unprocessed
79	}
80
81	pub fn processed(&self) -> &'a Context<T, B> {
82		self.processed
83	}
84}
85
86/// Processed context that also owns the original, unprocessed, context.
87pub struct ProcessedOwned<T, B> {
88	pub unprocessed: json_ld_syntax::context::Context,
89	pub processed: Context<T, B>,
90}
91
92impl<T, B> ProcessedOwned<T, B> {
93	pub fn new(unprocessed: json_ld_syntax::context::Context, processed: Context<T, B>) -> Self {
94		Self {
95			unprocessed,
96			processed,
97		}
98	}
99
100	pub fn unprocessed(&self) -> &json_ld_syntax::context::Context {
101		&self.unprocessed
102	}
103
104	pub fn processed(&self) -> &Context<T, B> {
105		&self.processed
106	}
107
108	pub fn as_ref(&self) -> ProcessedRef<T, B> {
109		ProcessedRef {
110			unprocessed: &self.unprocessed,
111			processed: &self.processed,
112		}
113	}
114}