Skip to content

Improve type check of keys #26

@kuy

Description

@kuy

Is your feature request related to a problem? Please describe.

In a table which has both partition key and sort key, rustc doesn't raise errors if I forget to call sort_key(...) method to pass sort key.

Describe the solution you'd like

raiden-derive could generate more precise signatures like fn get(&mut self, key: (K, K)) where K: IntoAttribute + Send instead of fn get(&mut self, key: impl IntoAttribute + Send) base on given definition of the struct.

Want to discuss

Abstract Key

In batch_get op, there are lots of conditional code generations like below.

https://github.com/raiden-rs/raiden/blob/94a77a238405acca7a048d397a6347297b7768b1/raiden-derive/src/ops/batch_get.rs#L73-L90

I want to reduce repeat by defining an abstract type for keys. This means that the type consists of impl IntoAttribute and (impl IntoAttribute, impl IntoAttribute). If I define the abstract type using enum, it looks like below.

enum Key {
  Pk(impl IntoAttribute),
  PkSk((impl IntoAttribute, impl IntoAttribute)),
}

However, this is annoying in its representation.

let keys = vec![("aaa", 2019), ("bbb", 2020), ("ccc", 2021)]; // looks naturally

let keys = vec![PkSk("aaa", 2019), PkSk("bbb", 2020), PkSk("ccc", 2021)]; // umm....

So finally, I stopped this approach.

Metadata

Metadata

Assignees

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