Skip to content

Feature Request: Allow key field to point to functions #21

Open

Description

@Swoorup

Description

Currently, the key field in the venndb library is limited to pointing to struct fields. We could an enhancement to allow the key field to point to functions inside the struct, providing more flexibility in key definitions and usage.

Example

#[derive(VennDB)]
#[venndb(key = "get_dynamic_key")]
struct ExampleStruct {
    #[venndb(key)]
    id: u32,
    name: String,
}

impl ExampleStruct {
    fn get_dynamic_key(&self) -> u32 {
    }
}

Benefits

Increased flexibility in defining keys for the venndb library.
Support for dynamic key generation based on custom logic.

Activity

  1. GlenDC commented on Aug 23, 2025

    @GlenDC
    Member

    Your proposal is legit. However it will have to be this instead:

    #[derive(VennDB)]
    struct ExampleStruct {
        #[venndb(key = "get_dynamic_key")]
        id: u32,
        name: String,
    }
    
    impl ExampleStruct {
        fn get_dynamic_key(&self) -> u32 {
        }
    }
    

    As you can have multiple keys for a single struct.

    Your proposal would mean that you can now do #[venndb(key)] (current only way to define a key) as well as #[venndb(key = "fn")].

    Would you be willing to implement this?
    I can accept the PR once all is well and happy to mentor you through it.

    My apologies for not seeing this earlier.
    Do feel free to join the discord of our FOSS org and poke me there if I do not
    respond fast enough. Sometimes I can miss stuff on Github. Or send me another tagged msg via github, that is also always possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions