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
use json_ld_core::ProcessingMode;
/// Expansion options.
#[derive(Clone, Copy, Default)]
pub struct Options {
/// Sets the processing mode.
pub processing_mode: ProcessingMode,
/// Term expansion policy.
///
/// Default is `Policy::Standard`.
pub policy: Policy,
/// If set to true, input document entries are processed lexicographically.
/// If false, order is not considered in processing.
pub ordered: bool,
}
impl Options {
pub fn unordered(self) -> Self {
Self {
ordered: false,
..self
}
}
}
impl From<Options> for json_ld_context_processing::Options {
fn from(options: Options) -> json_ld_context_processing::Options {
json_ld_context_processing::Options {
processing_mode: options.processing_mode,
..Default::default()
}
}
}
/// Key expansion policy.
///
/// The default behavior of the expansion algorithm
/// is to drop keys that are not defined in the context unless:
/// - there is a vocabulary mapping (`@vocab`) defined in the context; or
/// - the term contains a `:` character.
/// In other words, a key that cannot be expanded into an
/// IRI or a blank node identifier is dropped unless it contains a `:` character.
///
/// Sometimes, it is preferable to keep undefined keys in the
/// expanded document, or to forbid them completely by raising an error.
/// You can define your preferred policy using one of this type variant
/// with the [`Options::policy`] field.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Policy {
/// Relaxed policy.
///
/// Undefined keys are always kept in the expanded document
/// using the [`Id::Invalid`](json_ld_core::Id::Invalid) variant.
Relaxed,
/// Standard policy.
///
/// Every key that cannot be expanded into an
/// IRI or a blank node identifier is dropped unless it contains a `:` character.
Standard,
/// Strict policy.
///
/// Every key that cannot be expanded into an IRI or a blank node identifier
/// will raise an error unless the term contains a `:` character.
Strict,
/// Strictest policy.
///
/// Every key that cannot be expanded into an IRI or a blank node identifier
/// will raise an error.
Strictest,
}
impl Policy {
/// Returns `true` is the policy is `Strict` or `Strictest`.
pub fn is_strict(&self) -> bool {
matches!(self, Self::Strict | Self::Strictest)
}
}
impl Default for Policy {
fn default() -> Self {
Self::Standard
}
}