Add `ActiveValue::try_as_ref()`
Another helper method that I use very often and would like to upstream. Basically, a non-panicking version of ActiveValue::as_ref.
PR Info
-
Closes
-
Dependencies:
-
Dependents:
New Features
ActiveValue::try_as_ref()
Bug Fixes
Breaking Changes
Changes
Thanks. But is try_as_ref the best name? I am trying to find something similar in other Rust libraries.
I think, it's a good name because it's consistent with the existing as_ref, and there's also a third party try_as_traits::TryAsRef::try_as_ref for using this pattern generically. I've decided against adding an extra dependency because I don't need to be abstract & generic, and inherent methods are more discoverable.
In my dependent codebase, this helper is called ActiveValueExt::value. But when I was upstreaming it, I discovered that this name would be confusing in combination with existing into_value and into_wrapped_value which return Value rather than V.
Overall, it's up to you. I'm ok with other names, as long as they don't contain value. E.g. as_ref (if it wasn't already taken), borrow (you may not like it because it sounds like Borrow::borrow but has a different signature), get...
For other examples in the ecosystem, you can check out the methods on async_graphql::MaybeUndefined. It's a similar Option-like enum
Hey @Expurple, thanks for contributing!!
Maybe value or as_value? We already have unwrap, into_value and into_wrapped_value methods.
https://github.com/SeaQL/sea-orm/blob/c59e28f8c0319accc7177d3c37fe7bd2a8892b82/src/entity/active_model.rs#L815-L842
Just choose any one name that you agree to merge, then I make the edit and you merge it. The final approve decision is up to you anyway. I've already listed some options and explained why I prefer try_as_ref/borrow/get to value/as_value, but all of these will do the job and I'm not interested in bikeshedding
Hey @tyt2y3, perhaps value / as_value?
:tada: Released In 1.0.0-rc.5 :tada:
Thank you everyone for the contribution! This feature is now available in the latest release. Now is a good time to upgrade! Your participation is what makes us unique; your adoption is what drives us forward. You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.
:tada: Released In 1.0.0 :tada:
Thank you everyone for the contribution! This feature is now available in the latest release. Now is a good time to upgrade! Your participation is what makes us unique; your adoption is what drives us forward. You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.