Skip to content

Architecture: Key and Value traits have circular dependency #26

@drmingdrmer

Description

@drmingdrmer

Summary

The Key and Value traits have a circular dependency - each requires the other as an associated type.

Location

crates/kvapi/src/kvapi/key.rs:52-57

pub trait Key: KeyCodec + Debug {
    type ValueType: kvapi::Value;  // Key knows about Value
    // ...
}

crates/kvapi/src/kvapi/value.rs:20-21

pub trait Value: Debug {
    type KeyType: kvapi::Key;  // Value knows about Key
    // ...
}

Problem

This circular dependency:

  • Makes the traits harder to understand and implement separately
  • Creates unnecessary coupling between key and value abstractions
  • Complicates trait bounds in generic code
  • Prevents implementing one trait without the other

Impact

  • More complex generic signatures throughout the codebase
  • Harder to add new key or value types
  • Cognitive overhead when working with the API

Suggested Fix

Consider whether Value::KeyType is truly necessary. The dependency_keys() method could potentially accept string keys instead:

pub trait Value: Debug {
    // Remove KeyType association if not strictly needed
    fn dependency_keys(&self, key: &str) -> impl IntoIterator<Item = String>;
}

Or if bidirectional navigation is needed, use a separate KeyValuePair trait that brings them together.

Priority

P2 - API design improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions