-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support ?
and return
in the decorated function
#4
Support ?
and return
in the decorated function
#4
Conversation
1. BlockModifier implementation 2. Named block in the decorated function Anecdotal testing worked, need to write proper unit tests and add docs
…ls to compile for try on Option<_>
tests/retry_method_with_try.rs
Outdated
false | ||
} | ||
|
||
#[retry(BACKOFF_CONFIG, retry_if)] |
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.
This fails because the usage of ?
on an Option
gets modified by the block modifier, looking like below:
let result = 'block: {
{
break 'block Some(
match i32::from_str(int).ok() { // produces Option
Ok(val) => val, // creates matching code for Result
Err(err) => break 'block Err(err),
},
);
}
};
I've pushed a test that works for Result<T, E>, and one that fails for Option due to the modifier on try. I think I'm okay with ruling out using this on My initial thought is it's not possible to detect if the try operator is used on an Option or Result, as even parsing the return value of the function will fail if the user defines a custom type that isn't named Result or Option. Maybe I'm not aware of some darker magic that could work there though... |
…on the Error object in the Err arm, to support what happens automatically in a block where anyhow::Error is used
I haven't had much time to explore a full decorator function approach (parsing things like |
@Brendan-Blanchard sorry for going AWOL, broke my foot and work has been hectic. I've been using it in my project based on my current branch and it has been great, so I think this is definitely a good step in the right direction. |
Wow that's quite a week, I hope you're on the mend now. I've pushed changes to tests and docs that represent how it works now given your changes. Thanks for taking an interest and driving this forward! |
So far:
Local testing worked. Want to get main author's feedback, to discuss if this is the best approach.
Will require unit tests and added docs.
Perhaps split the block modifier to a separate file.