Closed ltfschoen closed 1 year ago
I haven't looked at it in detail, but why do you have basically the same struct with the same impls twice?
Your state should be just:
pub struct State {
pub editing: Editing,
pub name: String,
pub name_file_details: String,
pub table: Table,
pub table_file_details: Table,
pub entry: Entry,
pub entry_editing: bool,
pub qr_code: String,
}
Or better yet, since you have two tables going on and both have a name, do something like:
pub struct Content {
pub name: String,
pub table: Table,
}
pub struct State {
pub editing: Editing,
pub main: Content,
pub details: Content,
pub entry: Entry,
pub entry_editing: bool,
pub qr_code: String,
}
Then you can have Deref<Target = Table>
implemented for Content
, remove the one for State
and you could do state.main.columns()
or state.details.columns()
with no ambiguity.
Thanks for the tips. I actually considered only using Table
but made the wrong choice at the time 👶
I tried your suggestions and they work great, I pushed changes here https://github.com/ltfschoen/kobold/commit/833b66c8d0fe8a36b8c3a2c247ba512f11ba6793
In the csv example,
table
is a property ofState
https://github.com/maciejhirsz/kobold/blob/master/examples/csv_editor/src/state.rs#L13 andcolumns
androws
are properties ofTable
https://github.com/maciejhirsz/kobold/blob/master/examples/csv_editor/src/state.rs#L18 and we can usecolumns()
orrows()
to get them forTable
https://github.com/maciejhirsz/kobold/blob/master/examples/csv_editor/src/state.rs#L81 but in main.rs, its callingstate.columns()
andstate.rows()
in places like here https://github.com/maciejhirsz/kobold/blob/master/examples/csv_editor/src/main.rs#L59, but i think it should be callingstate.table.columns()
andstate.table.rows()
.otherwise you get conflicts, like in the invoice example here where both
Table
andTableFileDetails
have propertiescolumns
androws
, and also the methodscolumns()
androws()
, so i have to explicitly specify like herestate.table.columns()
andstate.table.rows()
, orstate.table_file_details.rows()
andstate.table_file_details.columns()
, otherwise i might get the wrong one. for example if i just usedstate.columns()
it'd outputcolumns 0..2
, but if i usedstate.table_file_details.columns()
it outputcolumns 0..10
, which was what i was afteri think it should even use
state.table.source
instead of juststate.source