Skip to main content

terms

Function terms 

Source
pub fn terms<P: Encrypt>(value: P) -> Result<Vec<Term>, TermsError>
Expand description

Every equality term of value, in walk order, without encrypting it.

It refuses every value encryption refuses, for the same reason at the same path (see Terms), so it never returns terms for a value that cannot be stored.

§Examples

use std::collections::BTreeMap;
use vitaminc_normalize::{domain, terms, NormalizeError, Step};

let mut user = BTreeMap::new();
user.insert("name", "Ada");
let found = terms(&user)?;
assert_eq!(found[0].path.steps(), [Step::Key("name".into())]);
assert_eq!(found[0].normalized.domain, domain::TEXT);

// U+0378 is unassigned in Unicode 16, so the name has no term.
user.insert("name", "\u{378}");
let refused = terms(&user).unwrap_err();
let term = refused.term().expect("refused by Terms");
assert_eq!(term.error(), NormalizeError::UnassignedCodePoint);
assert_eq!(term.path().steps(), [Step::Key("name".into())]);
// The message names neither the field nor its value.
assert_eq!(
    refused.to_string(),
    "no equality term: text contains a code point unassigned in Unicode 16"
);

// A uuid of three bytes cannot be encrypted, so it has no term either:
// `terms` refuses it as encryption does.
use vitaminc_aead::{Logical, Physical, Raw, Unencryptable};
let id = Raw(Some(Logical::Uuid), Physical::Bytes(&[0; 3]));
let refused = terms(id).unwrap_err();
let refusal = refused.refusal().expect("refused for its shape");
assert_eq!(refusal.reason(), Unencryptable::InvalidValue);

§Errors

TermsError: what Terms refuses, a value encryption would refuse included, or the source’s own failure.