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
use iref::IriBuf;
use json_ld_core::Context;
use rdf_types::BlankIdBuf;
use std::ops;

/// Processed context that also borrows the original, unprocessed, context.
pub struct Processed<'l, T = IriBuf, B = BlankIdBuf> {
	unprocessed: &'l json_ld_syntax::context::Context,
	processed: Context<T, B>,
}

impl<'l, T, B> Processed<'l, T, B> {
	pub(crate) fn new(
		unprocessed: &'l json_ld_syntax::context::Context,
		processed: Context<T, B>,
	) -> Self {
		Self {
			unprocessed,
			processed,
		}
	}

	pub fn unprocessed(&self) -> &'l json_ld_syntax::context::Context {
		self.unprocessed
	}

	pub fn into_processed(self) -> Context<T, B> {
		self.processed
	}

	pub fn as_ref(&self) -> ProcessedRef<'l, '_, T, B> {
		ProcessedRef {
			unprocessed: self.unprocessed,
			processed: &self.processed,
		}
	}

	pub fn into_owned(self) -> ProcessedOwned<T, B> {
		ProcessedOwned {
			unprocessed: self.unprocessed.clone(),
			processed: self.processed,
		}
	}
}

impl<'l, T, B> ops::Deref for Processed<'l, T, B> {
	type Target = Context<T, B>;

	fn deref(&self) -> &Self::Target {
		&self.processed
	}
}

impl<'l, T, B> ops::DerefMut for Processed<'l, T, B> {
	fn deref_mut(&mut self) -> &mut Self::Target {
		&mut self.processed
	}
}

/// Reference to a processed context that also borrows the original, unprocessed, context.
pub struct ProcessedRef<'l, 'a, T, B> {
	unprocessed: &'l json_ld_syntax::context::Context,
	processed: &'a Context<T, B>,
}

impl<'l, 'a, T, B> ProcessedRef<'l, 'a, T, B> {
	pub fn unprocessed(&self) -> &'l json_ld_syntax::context::Context {
		self.unprocessed
	}

	pub fn processed(&self) -> &'a Context<T, B> {
		self.processed
	}
}

/// Processed context that also owns the original, unprocessed, context.
pub struct ProcessedOwned<T, B> {
	unprocessed: json_ld_syntax::context::Context,
	processed: Context<T, B>,
}

impl<T, B> ProcessedOwned<T, B> {
	pub fn unprocessed(&self) -> &json_ld_syntax::context::Context {
		&self.unprocessed
	}

	pub fn processed(&self) -> &Context<T, B> {
		&self.processed
	}

	pub fn as_ref(&self) -> ProcessedRef<T, B> {
		ProcessedRef {
			unprocessed: &self.unprocessed,
			processed: &self.processed,
		}
	}
}