-
Notifications
You must be signed in to change notification settings - Fork 21
example: simplify transfer example #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh-blobs/pr/53/docs/iroh_blobs/ Last updated: 2025-02-21T09:49:03Z |
matheus23
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the node -> router rename, extracting the args into a variable with a comment in advance (and skipping the cmd), but I'm not convinced that parsing the args twice (once in main, checking the length and matching on args[0], then in e.g. receive again, checking the length again).
I think having a match like ["send", path] => ... or ["receive", ticket, path] => ... is much easier to read.
I'm also not super convinced that pulling out send and receive into functions is easier to understand. These are functions that are only called once, and in addition, they even have a hidden contract with the caller: E.g. in send it is assumed that args[1] won't panic, i.e. the args length had been checked before. Perhaps it would be better to separate the argument parsing in main from send and receive and pass the parsed arguments into these functions, if we want to preserve the split out functions.
I have never seen anyone use this to parse arguments tbh, and was very confused when I read it, which is why I changed it |
well it's not reparsing, just checking in stages, given the information available |
that's fair |
Well, I guess the haskeller in me came out. But like, this is just pattern matching, right? What specifically was confusing? Isn't this a really nice way to match CLI args, it looks a lot like the writing down... well.. the pattern. I mean, if others agree - fine, but IMO the pattern matching reads better. |
🤣
the line before for the most part is really hard to parse and understand |
Ah okay, perfect. Can we improve that part and keep the pattern matching? 🥺 |
I'll try 😅 |
matheus23
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dignifiedquire would you agree with this set of changes?
This now
- renames
nodetorouter - extracts out
args_refsand explains it with a comment (and uses.as_slice()instead of&[..]) - skips the
_cmdin the args - generally uses
let x: X = str.parse()instead ofX::from_str - uses
std::path::absoluteinstead of.canonicalize(I seem to get errors with canoncialize?) - uses
blobs.client().exportinstead oftokio::io::copying the file out
I decided against extracting out the functions, and also opted for the pattern matching.
And I went for .finish().await? instead of just .await? on the progress structs. That one I'm not super sure on. I do think being explicit here is helpful. If people have this open in an editor, they can click on the .finish() and see where it comes from - or they can search on docs.rs for structs that have such a method and will see results.
Thoughts?
|
LGTM 🚢 |
they both suck, I am fine either way, we will make this API better in the future (TM) |
matheus23
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting dig's approval into something that github accepts 🙃
Description
Breaking Changes
Notes & open questions
Change checklist