json-ld 0.22.0

JSON-LD implementation
Documentation
use crate::{
	JsonLdProcessingMode,
	algorithms::{
		context_processing::JsonLdContextProcessingOptions, expansion::JsonLdExpansionOptions,
	},
};

/// Compaction options.
#[derive(Clone, Copy)]
pub struct JsonLdCompactionOptions {
	/// JSON-LD processing mode.
	pub processing_mode: JsonLdProcessingMode,

	/// Determines if IRIs are compacted relative to the provided base IRI or document location when compacting.
	pub compact_to_relative: bool,

	/// If set to `true`, arrays with just one element are replaced with that element during compaction.
	/// If set to `false`, all arrays will remain arrays even if they have just one element.
	pub compact_arrays: bool,

	/// If set to `true`, properties are processed by lexical order.
	/// If `false`, order is not considered in processing.
	pub ordered: bool,
}

impl JsonLdCompactionOptions {
	pub fn unordered(self) -> Self {
		Self {
			ordered: false,
			..self
		}
	}
}

impl From<JsonLdCompactionOptions> for JsonLdContextProcessingOptions {
	fn from(options: JsonLdCompactionOptions) -> Self {
		Self {
			processing_mode: options.processing_mode,
			..Self::default()
		}
	}
}

impl From<JsonLdExpansionOptions> for JsonLdCompactionOptions {
	fn from(options: JsonLdExpansionOptions) -> Self {
		Self {
			processing_mode: options.processing_mode,
			ordered: options.ordered,
			..Self::default()
		}
	}
}

impl Default for JsonLdCompactionOptions {
	fn default() -> Self {
		Self {
			processing_mode: JsonLdProcessingMode::default(),
			compact_to_relative: true,
			compact_arrays: true,
			ordered: false,
		}
	}
}