# Derive Macro for rust

**URL:** <https://forum.typedb.com/t/derive-macro-for-rust/701>\
**Category:** TypeQL\
**Tags:** schema-design, typedb-client-api\
**Created:** [14 August 2025 15:05 UTC](https://forum.typedb.com/t/derive-macro-for-rust/701 "2025-08-14T15:05:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sevki](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/sevki/32/252_2.png) [@sevki](https://forum.typedb.com/u/sevki)\
**Post date:** [14 August 2025 15:05 UTC](https://forum.typedb.com/t/derive-macro-for-rust/701/1 "2025-08-14T15:05:29Z")

</div>

Hi folks,

I’m Sevki, I’m new here. I have been searching for a more _rusty_™️ way to generate schemas.

something like,

```rust
#[derive(Relation)]
enum Employment {
    #[role]
    Employee,
    #[role]
    Employer,
}

// Rust code
#[derive(Entity)]
#[abs]
pub struct Person {
    #[key]
    email: String,
    #[owns]
    full_name: String,
    #[owns]
    age: i32,
    #[plays(Employment::Employee)]
    employment: Option<Employment>,
}

```

I have started to try and build something like this, would be happy to share it with people if they can see any value in it.

The derive bits as you can imagine are quite straight forward.

What I am currently working on is

```rust
#[derive(QueryAnswers)]
#[query("match $person isa person, has name $name, has age $age;")]
struct PersonQuery;

```

which will generate a

```rust
struct PersonAnswer {
    name: String,
    age: i64,
}

#[derive(Debug, Clone)]
enum PersonError {
    InvalidName,
    InvalidAge,
}

impl TryFrom<ConceptRow> for PersonAnswer {
    type Error = PersonError;

    fn try_from(value: ConceptRow) -> Result<Self, Self::Error> {
        Ok(Self {
            name: value
                .get("name")
                .unwrap()
                .unwrap()
                .try_get_string()
                .unwrap()
                .into(),
            age: value
                .get("age")
                .map_err(|_| PersonError::InvalidAge)?
                .ok_or(PersonError::InvalidAge)?
                .try_get_integer()
                .unwrap(),
        })
    }
} 

```

So my question is, I’m really really new to typedb and would like to contribute somehthing like this, if anyone wants to help me onboard and mentor me on landing this.

cheers,

s.
