ParseObjectKey

Trait ParseObjectKey 

Source
pub trait ParseObjectKey<'doc>:
    Sized
    + Eq
    + Hash
    + Ord {
    // Required methods
    fn from_object_key(key: &'doc ObjectKey) -> Result<Self, ParseErrorKind>;
    fn from_extension_ident(ident: &Identifier) -> Result<Self, ParseErrorKind>;
}
Expand description

Trait for types that can be used as object keys when parsing from Eure documents.

This trait abstracts over key types that can be used in Map<K, V>, supporting owned (ObjectKey), borrowed (&'doc ObjectKey), and primitive types (bool, BigInt, String) for type-constrained maps.

§Lifetime Parameter

The 'doc lifetime ties the parsed key to the document’s lifetime, allowing zero-copy parsing for reference types.

§Type Constraints

Implementors must satisfy:

  • Eq + Hash for use with AHashMap (std feature)
  • Ord for use with BTreeMap (no_std)

§Examples

use eure_document::{EureDocument, Map, ObjectKey, ParseDocument};

// Parse map with borrowed keys (zero-copy)
let map: Map<&ObjectKey, String> = doc.parse(root_id)?;

// Parse map with owned keys
let map: Map<ObjectKey, String> = doc.parse(root_id)?;

// Parse map with type-constrained keys
let map: Map<String, i32> = doc.parse(root_id)?;

Required Methods§

Source

fn from_object_key(key: &'doc ObjectKey) -> Result<Self, ParseErrorKind>

Parse an object key from the given ObjectKey reference in the document.

§Arguments
  • key - Reference to the ObjectKey in the document’s NodeMap
§Returns

Returns Self on success, or ParseErrorKind if the key cannot be converted to the target type (e.g., trying to parse a Bool as String).

§Errors

Returns ParseErrorKind::TypeMismatch when the ObjectKey variant doesn’t match the expected type.

Source

fn from_extension_ident(ident: &Identifier) -> Result<Self, ParseErrorKind>

Parse a key from an extension identifier.

Extension keys are always string identifiers. This method converts them to the target key type. This is separate from from_object_key because extension identifiers don’t have 'doc lifetime (they’re not ObjectKeys stored in the document’s NodeMap).

§Errors

Returns ParseErrorKind::TypeMismatch if the target type cannot be constructed from an identifier (e.g., borrowed &ObjectKey or numeric keys).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ParseObjectKey<'_> for bool

Source§

impl ParseObjectKey<'_> for String

Source§

impl ParseObjectKey<'_> for BigInt

Implementors§

Source§

impl ParseObjectKey<'_> for ObjectKey

Source§

impl<'doc> ParseObjectKey<'doc> for &'doc ObjectKey