ParseObjectKey

Trait ParseObjectKey 

Source
pub trait ParseObjectKey<'doc>:
    Sized
    + Eq
    + Hash
    + Ord {
    // Required method
    fn from_object_key(key: &'doc ObjectKey) -> 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.

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