h-be / acorn-hc

the holochain backend for Acorn
Other
30 stars 5 forks source link

Use rust skills to clean up deeeep nesting code in fetch_goals #54

Closed Connoropolous closed 4 years ago

Connoropolous commented 5 years ago

The point of this code is to KEEP the original addresses of the nodes, since they are what "edges" reference

https://github.com/h-be/acorn-hc/blob/7eb544d26e5b92ca74aae4aea4d0d9f378ca182b/zomes/holo_acorn/code/src/lib.rs#L575-L603

@thedavidmeister can you take a peek at this and give comment? possibly fix?

Connoropolous commented 5 years ago

I think Will and I used our undeveloped rust skills to write this, and it was really sad that this was the code that worked the way we wanted to, but seemed to look horrible, and I imagine there MUST be a better way

hector0513 commented 5 years ago

Hi, sorry if I shouldn't have stepped in but I saw the issue and thought it would be a quick task. https://github.com/h-be/acorn-hc/pull/56

Connoropolous commented 5 years ago

Stepping in is fine. Now we've made some progress on this, I will take David off and assign you

Connoropolous commented 5 years ago

@thedavidmeister could still chime in with advice if you have some, and we haven't solved this by the time you look into it

thedavidmeister commented 5 years ago

@Connoropolous or @hector0513 can you do the destructuring in one step?

if let Ok(Some(Entry::App(_, entry_value) {
 ..
} else {
 Err(ZomeApiInternal::Internal(""get_links did not return an app entry".into()))
}
Connoropolous commented 5 years ago

Hector discovered get_as_type in the HDK and in some ways it does that for us. It is cool to see how it might be done without though

thedavidmeister commented 5 years ago

@Connoropolous mhmm, i think destructuring matches is "the rust way" in general, as this is also what clippy says to do (obviously clippy doesn't know anything about the hdk though)

Connoropolous commented 5 years ago

I didn't know the syntax you used there was called destructuring, so even that's a helpful lesson