Skip to main content

json_ld/algorithms/compaction/
options.rs

1use crate::{
2	JsonLdProcessingMode,
3	algorithms::{
4		context_processing::JsonLdContextProcessingOptions, expansion::JsonLdExpansionOptions,
5	},
6};
7
8/// Compaction options.
9#[derive(Clone, Copy)]
10pub struct JsonLdCompactionOptions {
11	/// JSON-LD processing mode.
12	pub processing_mode: JsonLdProcessingMode,
13
14	/// Determines if IRIs are compacted relative to the provided base IRI or document location when compacting.
15	pub compact_to_relative: bool,
16
17	/// If set to `true`, arrays with just one element are replaced with that element during compaction.
18	/// If set to `false`, all arrays will remain arrays even if they have just one element.
19	pub compact_arrays: bool,
20
21	/// If set to `true`, properties are processed by lexical order.
22	/// If `false`, order is not considered in processing.
23	pub ordered: bool,
24}
25
26impl JsonLdCompactionOptions {
27	pub fn unordered(self) -> Self {
28		Self {
29			ordered: false,
30			..self
31		}
32	}
33}
34
35impl From<JsonLdCompactionOptions> for JsonLdContextProcessingOptions {
36	fn from(options: JsonLdCompactionOptions) -> Self {
37		Self {
38			processing_mode: options.processing_mode,
39			..Self::default()
40		}
41	}
42}
43
44impl From<JsonLdExpansionOptions> for JsonLdCompactionOptions {
45	fn from(options: JsonLdExpansionOptions) -> Self {
46		Self {
47			processing_mode: options.processing_mode,
48			ordered: options.ordered,
49			..Self::default()
50		}
51	}
52}
53
54impl Default for JsonLdCompactionOptions {
55	fn default() -> Self {
56		Self {
57			processing_mode: JsonLdProcessingMode::default(),
58			compact_to_relative: true,
59			compact_arrays: true,
60			ordered: false,
61		}
62	}
63}