scylladb/scylla-rust-driver

Ignore field feature

GoranBrkuljan opened this issue · 2 comments

I thought to use some free time to migrate charybdis lib to new serialization API, but one feature we are missing is ignore/skip attributes for non-db struct fields. Is anything planned for this one?

We have model-heavy logic that relays on cached fields

struct Foo {
    id: Uuid,
    title: Text,
    
    #[charybdis(ignore)]
    pub cached_field: Option<Val>,
}

impl Foo {
    pub fn cached_field(&self) -> Option<Val> {
        if self.cached_field.is_none() {
            self.cached_field = compute();
        }

        self.cached_field
    }
}

Previously this worked because charybdis manually implemented ValueList trait for structs, but now logic for SerializeRow is bit more complicated and it would be cool if this is implemented on driver level.

This seems like a useful feature, I think we could add it.

In the meantime you can, as you said, implement the trait manually, and I'd encourage you to try it.
While it may seem more complicated now, it should actually be easier and less bug prone, as the new API does some things for you that you had to do manually before and prevents some types of bugs either during compilation or runtime.

Got it, I'll try. However, considering that manual implementation also goes within proc macro, I think I will end up with copy-pasting the code that you already have for SerializeRow Derive with additional ignore attribute. However, if ignore feature is implemented within driver I just need to proxy flag from Charybdis lib to Scylla driver itself. ATM I am not aware of benefit of manual implementation, but there are might some like error mapping from Scylla driver to Charybdis.