Skip to main content

Rule

Struct Rule 

Source
pub struct Rule {
    pub path: Path,
    pub action: Action,
}
Expand description

One HL7 path and what to do at it.

The path is an er7::Path, so its notation and semantics are er7’s (that crate’s spec §8.1): an omitted occurrence index means every segment of that name and every repetition of that field, which is what lets OBX-5 cover a message with forty results.

A rule whose action is Action::Keep accepts the position it names; a rule with any other action rejects it. Where both name the same leaf, the rejecting one wins, whichever order they are in (D19, spec §2.4).

Example:

use er7_redact::{Action, Rule};

let rule = Rule::new("PID-5", Action::redacted())?;
assert_eq!(rule.path.segment, "PID");
assert_eq!(rule.to_string(), "PID-5 replace REDACTED");

// Or read one as a policy file spells it.
assert_eq!(Rule::parse("PID-7 first 4")?.action, Action::First(4));

Fields§

§path: Path

Where the rule applies.

§action: Action

What it does there.

Implementations§

Source§

impl Rule

Source

pub fn new(path: &str, action: Action) -> Result<Rule, Error>

A rule from a path and an action.

§Errors

Error::Er7 wrapping er7::Error::BadPath when path is not an HL7 path — a zero index, a missing field number, trailing text.

Source

pub fn parse(line: &str) -> Result<Rule, Error>

Read one policy line: a path, whitespace, an action (spec §6).

Example:

use er7_redact::{Action, Rule};

let rule = Rule::parse("  OBX[2]-5   replace NOT ON FILE  ")?;
assert_eq!(rule.path.to_string(), "OBX[2]-5");
assert_eq!(rule.action, Action::Replace("NOT ON FILE".to_string()));

assert!(Rule::parse("PID-5").is_err());       // no action
assert!(Rule::parse("PID-0 clear").is_err()); // not a path
§Errors

Error::BadPolicy naming the rule and the problem: a line with no action, an action that does not exist, or a path that is not a path.

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The path and the action, separated by one space — the policy file spelling, so a rule written out reads back as itself.

Source§

impl Eq for Rule

Source§

impl PartialEq for Rule

Source§

fn eq(&self, other: &Rule) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rule

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

§

impl UnwindSafe for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.