pub struct KnownValue { /* private fields */ }Expand description
A value in a namespace of unsigned integers that represents a stand-alone ontological concept.
Known Values provide a compact, deterministic way to represent commonly used ontological concepts such as relationships between entities, classes of entities, properties, or enumerated values. They are particularly useful as predicates in Gordian Envelope assertions, offering a more compact and deterministic alternative to URIs. However, known values are not exclusive to Gordian Envelopes and can be used in any context where a compact, unique identifier for a concept is needed.
A Known Value is represented as a 64-bit unsigned integer with an optional human-readable name. This approach ensures:
- Compact binary representation - Each Known Value requires only 1-9 bytes depending on value range
- Deterministic encoding - Every concept has exactly one valid binary representation
- Enhanced security - Eliminates URI manipulation vulnerabilities
- Standardized semantics - Values are registered in a central registry
While Known Values are most commonly used as predicates in assertions, they can appear in any position in an Envelope (subject, predicate, or object).
§Examples
use known_values::KnownValue;
// Create a Known Value with a numeric value
let known_value = KnownValue::new(42);
assert_eq!(known_value.value(), 42);
// Create a Known Value with a name
let named_value = KnownValue::new_with_name(1u64, "isA".to_string());
assert_eq!(named_value.value(), 1);
assert_eq!(named_value.name(), "isA");
// Use a pre-defined Known Value from the registry
let is_a_value = known_values::IS_A;
assert_eq!(is_a_value.value(), 1);
assert_eq!(is_a_value.name(), "isA");§Specification
Known Values are defined in BCR-2023-002 and implemented as an Envelope extension in BCR-2023-003.
Implementations§
Source§impl KnownValue
impl KnownValue
Sourcepub fn new(value: u64) -> Self
pub fn new(value: u64) -> Self
Creates a new KnownValue with the given numeric value and no name.
§Examples
use known_values::KnownValue;
let known_value = KnownValue::new(42);
assert_eq!(known_value.value(), 42);Sourcepub fn new_with_name<T: Into<u64>>(value: T, assigned_name: String) -> Self
pub fn new_with_name<T: Into<u64>>(value: T, assigned_name: String) -> Self
Creates a KnownValue with the given value and associated name.
This function accepts any type that can be converted into a u64 and
a String for the name. The name is stored as a dynamic value.
§Examples
use known_values::KnownValue;
let known_value = KnownValue::new_with_name(1u64, "isA".to_string());
assert_eq!(known_value.value(), 1);
assert_eq!(known_value.name(), "isA");Sourcepub const fn new_with_static_name(value: u64, name: &'static str) -> Self
pub const fn new_with_static_name(value: u64, name: &'static str) -> Self
Creates a KnownValue at compile time with the given value and static name.
This function is used primarily with the const_known_value! macro to
define known values as constants in the registry.
§Examples
use known_values::KnownValue;
// This is similar to how registry constants are defined
const IS_A: KnownValue = KnownValue::new_with_static_name(1, "isA");
assert_eq!(IS_A.value(), 1);
assert_eq!(IS_A.name(), "isA");Sourcepub fn value(&self) -> u64
pub fn value(&self) -> u64
Returns the numeric value of the KnownValue.
This is the raw 64-bit unsigned integer that identifies the concept.
§Examples
assert_eq!(known_values::IS_A.value(), 1);
assert_eq!(known_values::NOTE.value(), 4);Sourcepub fn assigned_name(&self) -> Option<&str>
pub fn assigned_name(&self) -> Option<&str>
Returns the assigned name of the KnownValue, if one exists.
§Examples
use known_values::KnownValue;
let named_value = KnownValue::new_with_name(1u64, "isA".to_string());
assert_eq!(named_value.assigned_name(), Some("isA"));
let unnamed_value = KnownValue::new(42);
assert_eq!(unnamed_value.assigned_name(), None);Sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Returns a human-readable name for the KnownValue.
If the KnownValue has an assigned name, that name is returned. Otherwise, the string representation of the numeric value is returned.
§Examples
use known_values::KnownValue;
let named_value = KnownValue::new_with_name(1u64, "isA".to_string());
assert_eq!(named_value.name(), "isA");
let unnamed_value = KnownValue::new(42);
assert_eq!(unnamed_value.name(), "42");Trait Implementations§
Source§impl CBORTagged for KnownValue
Specifies the CBOR tag used for KnownValue.
impl CBORTagged for KnownValue
Specifies the CBOR tag used for KnownValue.
Source§impl CBORTaggedDecodable for KnownValue
Creates a KnownValue from untagged CBOR.
impl CBORTaggedDecodable for KnownValue
Creates a KnownValue from untagged CBOR.
Source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for KnownValue
Provides the untagged CBOR representation of a KnownValue.
impl CBORTaggedEncodable for KnownValue
Provides the untagged CBOR representation of a KnownValue.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for KnownValue
impl Clone for KnownValue
Source§fn clone(&self) -> KnownValue
fn clone(&self) -> KnownValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KnownValue
impl Debug for KnownValue
Source§impl DigestProvider for KnownValue
Provides a cryptographic digest for a KnownValue.
impl DigestProvider for KnownValue
Provides a cryptographic digest for a KnownValue.
Source§impl Display for KnownValue
Formats the KnownValue for display.
impl Display for KnownValue
Formats the KnownValue for display.
If a name is assigned, the name is displayed. Otherwise, the numeric value is displayed.
Source§impl From<KnownValue> for CBOR
Converts a KnownValue to CBOR.
impl From<KnownValue> for CBOR
Converts a KnownValue to CBOR.
Source§fn from(value: KnownValue) -> Self
fn from(value: KnownValue) -> Self
Source§impl From<i32> for KnownValue
Creates a KnownValue from an i32.
impl From<i32> for KnownValue
Creates a KnownValue from an i32.
Source§impl From<u64> for KnownValue
Creates a KnownValue from a u64.
impl From<u64> for KnownValue
Creates a KnownValue from a u64.
Source§impl From<usize> for KnownValue
Creates a KnownValue from a usize.
impl From<usize> for KnownValue
Creates a KnownValue from a usize.
Source§impl Hash for KnownValue
Hash implementation for KnownValue that considers only the numeric value.
impl Hash for KnownValue
Hash implementation for KnownValue that considers only the numeric value.
Source§impl PartialEq for KnownValue
Equality for KnownValue is based solely on the numeric value, ignoring the
name.
impl PartialEq for KnownValue
Equality for KnownValue is based solely on the numeric value, ignoring the name.
Source§impl TryFrom<CBOR> for KnownValue
Attempts to convert CBOR to a KnownValue.
impl TryFrom<CBOR> for KnownValue
Attempts to convert CBOR to a KnownValue.
impl Eq for KnownValue
KnownValue implements Eq since equality is based on the numeric value, which can be compared for equality.