Closed ltfschoen closed 1 year ago
Can't do that. You can chain derefs so that if &T
derefs into &U
, which derefs into &V
, then you can call methods from both U
and V
on T
, but you can never have more than one Deref
target for any given type.
If you need multiples you need to implement AsRef<T>
of which you can have multiple. In this case though you should just access table_file_details
(maybe just call it file_details
?) by field name.
I'm trying to make this Invoice example, here is the latest.
It uses code from csv_editor and todomvc. In the csv_editor example
Table
is used to store a table of rows and columns in theState
after the data is loaded from a CSV file no. 1 and it usesDeref
andDerefMut
here forTable
In the Invoice example, i added another struct
TableFileDetails
here that stores a separate table of rows and columns in theState
after the data is loaded from a different CSV file no. 2But I don't know how to implement
Deref
andDerefMut
for bothTable
andTableFileDetails
that are both used byState
?In the
DerefMut
docs they only give this example https://doc.rust-lang.org/std/ops/trait.DerefMut.html#examples of a "struct with a single field which is modifiable by dereferencing the struct".If I follow along with trying to use their example I end up with:
But then I get a lot of errors that I try to resolve, but the main one is the following:
And I can't see how to to return multiple targets from
deref
andderef_mut