[Merged by Bors] - Add try_* to add_slot_edge, add_node_edge#6720
[Merged by Bors] - Add try_* to add_slot_edge, add_node_edge#6720torsteingrindvik wants to merge 3 commits intobevyengine:mainfrom
Conversation
Signed-off-by: Torstein Grindvik <torstein.grindvik@nordicsemi.no>
alice-i-cecile
left a comment
There was a problem hiding this comment.
On board with this direction: I like this as an API pattern a lot.
I'm noticing the same pattern node_id().unwrap() while reviewing. Should we change that too? Should it be in the same PR?
IceSentry
left a comment
There was a problem hiding this comment.
Oh wow, such a simple change but it makes the render graph a lot nicer!
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
|
@alice-i-cecile About I saw in rustlang that there is precedence for having a So should I make the change for |
|
I would use |
|
I'll use that then, it's unsurprising which is good. I was a bit thrown off by this: https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter But I'm not sure what the justification is there and anyway I see Bevy uses a lot of I'll update the description. |
|
Yeah, it's pretty much a bevy convention that when you want a fallible getter you add the |
Signed-off-by: Torstein Grindvik <torstein.grindvik@nordicsemi.no>
|
bors r+ |
|
Ok, that's good to know. Hopefully CI passes, there was a strange error last run. |
# Objective `add_node_edge` and `add_slot_edge` are fallible methods, but are always used with `.unwrap()`. `input_node` is often unwrapped as well. This points to having an infallible behaviour as default, with an alternative fallible variant if needed. Improves readability and ergonomics. ## Solution - Change `add_node_edge` and `add_slot_edge` to panic on error. - Change `input_node` to panic on `None`. - Add `try_add_node_edge` and `try_add_slot_edge` in case fallible methods are needed. - Add `get_input_node` to still be able to get an `Option`. --- ## Changelog ### Added - `try_add_node_edge` - `try_add_slot_edge` - `get_input_node` ### Changed - `add_node_edge` is now infallible (panics on error) - `add_slot_edge` is now infallible (panics on error) - `input_node` now panics on `None` ## Migration Guide Remove `.unwrap()` from `add_node_edge` and `add_slot_edge`. For cases where the error was handled, use `try_add_node_edge` and `try_add_slot_edge` instead. Remove `.unwrap()` from `input_node`. For cases where the option was handled, use `get_input_node` instead. Co-authored-by: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
|
Pull request successfully merged into main. Build succeeded:
|
# Objective `add_node_edge` and `add_slot_edge` are fallible methods, but are always used with `.unwrap()`. `input_node` is often unwrapped as well. This points to having an infallible behaviour as default, with an alternative fallible variant if needed. Improves readability and ergonomics. ## Solution - Change `add_node_edge` and `add_slot_edge` to panic on error. - Change `input_node` to panic on `None`. - Add `try_add_node_edge` and `try_add_slot_edge` in case fallible methods are needed. - Add `get_input_node` to still be able to get an `Option`. --- ## Changelog ### Added - `try_add_node_edge` - `try_add_slot_edge` - `get_input_node` ### Changed - `add_node_edge` is now infallible (panics on error) - `add_slot_edge` is now infallible (panics on error) - `input_node` now panics on `None` ## Migration Guide Remove `.unwrap()` from `add_node_edge` and `add_slot_edge`. For cases where the error was handled, use `try_add_node_edge` and `try_add_slot_edge` instead. Remove `.unwrap()` from `input_node`. For cases where the option was handled, use `get_input_node` instead. Co-authored-by: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
# Objective `add_node_edge` and `add_slot_edge` are fallible methods, but are always used with `.unwrap()`. `input_node` is often unwrapped as well. This points to having an infallible behaviour as default, with an alternative fallible variant if needed. Improves readability and ergonomics. ## Solution - Change `add_node_edge` and `add_slot_edge` to panic on error. - Change `input_node` to panic on `None`. - Add `try_add_node_edge` and `try_add_slot_edge` in case fallible methods are needed. - Add `get_input_node` to still be able to get an `Option`. --- ## Changelog ### Added - `try_add_node_edge` - `try_add_slot_edge` - `get_input_node` ### Changed - `add_node_edge` is now infallible (panics on error) - `add_slot_edge` is now infallible (panics on error) - `input_node` now panics on `None` ## Migration Guide Remove `.unwrap()` from `add_node_edge` and `add_slot_edge`. For cases where the error was handled, use `try_add_node_edge` and `try_add_slot_edge` instead. Remove `.unwrap()` from `input_node`. For cases where the option was handled, use `get_input_node` instead. Co-authored-by: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
# Objective `add_node_edge` and `add_slot_edge` are fallible methods, but are always used with `.unwrap()`. `input_node` is often unwrapped as well. This points to having an infallible behaviour as default, with an alternative fallible variant if needed. Improves readability and ergonomics. ## Solution - Change `add_node_edge` and `add_slot_edge` to panic on error. - Change `input_node` to panic on `None`. - Add `try_add_node_edge` and `try_add_slot_edge` in case fallible methods are needed. - Add `get_input_node` to still be able to get an `Option`. --- ## Changelog ### Added - `try_add_node_edge` - `try_add_slot_edge` - `get_input_node` ### Changed - `add_node_edge` is now infallible (panics on error) - `add_slot_edge` is now infallible (panics on error) - `input_node` now panics on `None` ## Migration Guide Remove `.unwrap()` from `add_node_edge` and `add_slot_edge`. For cases where the error was handled, use `try_add_node_edge` and `try_add_slot_edge` instead. Remove `.unwrap()` from `input_node`. For cases where the option was handled, use `get_input_node` instead. Co-authored-by: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
Objective
add_node_edgeandadd_slot_edgeare fallible methods, but are always used with.unwrap().input_nodeis often unwrapped as well.This points to having an infallible behaviour as default, with an alternative fallible variant if needed.
Improves readability and ergonomics.
Solution
add_node_edgeandadd_slot_edgeto panic on error.input_nodeto panic onNone.try_add_node_edgeandtry_add_slot_edgein case fallible methods are needed.get_input_nodeto still be able to get anOption.Changelog
Added
try_add_node_edgetry_add_slot_edgeget_input_nodeChanged
add_node_edgeis now infallible (panics on error)add_slot_edgeis now infallible (panics on error)input_nodenow panics onNoneMigration Guide
Remove
.unwrap()fromadd_node_edgeandadd_slot_edge.For cases where the error was handled, use
try_add_node_edgeandtry_add_slot_edgeinstead.Remove
.unwrap()frominput_node.For cases where the option was handled, use
get_input_nodeinstead.