-
Notifications
You must be signed in to change notification settings - Fork 357
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
Make pair extensible 2 #1106
Make pair extensible 2 #1106
Conversation
Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
I keep looking at these PRs and can't stop thinking that by the time we're doing Doesn't |
This is a good point. I would say, create a specific issue for it, and let's see how it looks. |
Wise words. This is in line with my feeling that we try to do too many things with one symbol. What if we leave |
OK with me. |
Sounds pretty good! |
The term |
|
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 strongly oppose changing the names to A and B, but rather keep K and V.
Using the natural ordering for types makes sense. Curious as to what level of contract breakage this makes (not a strong argument, but at least good to know). Can you do a brief check of the cw-plus/contracts for usages of Pair?
/// A Key-Value pair, returned from our iterators | ||
pub type Pair<V = Vec<u8>> = (Vec<u8>, V); | ||
/// A pair of values, returned from our iterators | ||
pub type Pair<A = Vec<u8>, B = Vec<u8>> = (A, B); |
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 am strongly against using A and B here. This will only add to more dev confusion.
At least having some type hints would be good. I commented on the issue to the same effect.
@@ -101,7 +101,7 @@ fn range_bounds(start: Option<&[u8]>, end: Option<&[u8]>) -> impl RangeBounds<Ve | |||
type BTreeMapPairRef<'a, T = Vec<u8>> = (&'a Vec<u8>, &'a T); | |||
|
|||
#[cfg(feature = "iterator")] | |||
fn clone_item<T: Clone>(item_ref: BTreeMapPairRef<T>) -> Pair<T> { | |||
fn clone_item<T: Clone>(item_ref: BTreeMapPairRef<T>) -> Pair<Vec<u8>, T> { |
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 see this as a cleaner approach than using <V, K> types, but also more breaking. (Switching the order of arguments to be (v, k)
would be MUCH more breaking.
My question is how much does this break contract code. This will affect storage-plus, but if we update that (one hour maybe), then do we have to also update all the contracts that use range? Or is this just implicit info used by the compiler.
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 think it's just an implicit / type alias thing. Did the change to (K,V)
in cw-plus #432 and it was pretty straightforward.
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.
Sounds good
I agree with the idea to leave Pair as it is now, and use (K, V) where both are defined. I also searched for all usages of Pair in cw-plus contracts and only found 2. In cw721-base and cw1155-base: fn parse_approval(item: StdResult<Pair<Expiration>>) -> StdResult<cw721::Approval> {
item.and_then(|(k, expires)| {
let spender = String::from_utf8(k)?;
Ok(cw721::Approval { spender, expires })
})
} I assume this is very seldom used by other contract devs, or outside of storage-plus really. Feel free to rename to |
I guess time to close this, along with #1101? |
Thank you for the great discussion and inputs from everyone! |
This is a (breaking) version of
Pair
, which supports the natural order of fields. Closes #1100.