Skip to content
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 life-timed references in UniqueIndex and MultiIndex keys #233

Closed
maurolacy opened this issue Mar 4, 2021 · 1 comment
Closed

Comments

@maurolacy
Copy link
Contributor

maurolacy commented Mar 4, 2021

We're currently using PkOwned for MultiIndex and UniqueIndex keys. See also related #199, for another attempt to remove PkOwned.

This is what we get when changing the name MultiIndex to use &[u8] instead of PkOwned (in the indexed_map.rs tests):

   Compiling cw-storage-plus v0.5.0 (/usr2/home/mauro/work/cosmwasm-plus/packages/storage-plus)
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
   --> packages/storage-plus/src/indexed_map.rs:209:50
    |
209 |             name: MultiIndex::new(|d, k| (d.name.as_ref(), &*k), "data", "data__name"),
    |                                                  ^^^^^^
    |
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 209:35...
   --> packages/storage-plus/src/indexed_map.rs:209:35
    |
209 |             name: MultiIndex::new(|d, k| (d.name.as_ref(), &*k), "data", "data__name"),
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that reference does not outlive borrowed content
   --> packages/storage-plus/src/indexed_map.rs:209:43
    |
209 |             name: MultiIndex::new(|d, k| (d.name.as_ref(), &*k), "data", "data__name"),
    |                                           ^^^^^^
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 207:18...
   --> packages/storage-plus/src/indexed_map.rs:207:18
    |
207 |     fn build_map<'a>() -> IndexedMap<'a, &'a [u8], Data, DataIndexes<'a>> {
    |                  ^^
note: ...so that the expression is assignable
   --> packages/storage-plus/src/indexed_map.rs:216:9
    |
216 |         IndexedMap::new("data", indexes)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected `indexed_map::IndexedMap<'a, &'a [u8], _, DataIndexes<'a>>`
               found `indexed_map::IndexedMap<'_, &[u8], _, DataIndexes<'_>>`

error: aborting due to previous error

Analyze if we can use &[u8] for keys / subkeys in UniqueIndex and MultiIndex, after resolving these lifetime conflicts.
As a reference, Map allows using &[u8] for keys without issues.

@maurolacy maurolacy changed the title Support life-timed references in UniqueIndex and MultiIndex Support life-timed references in UniqueIndex and MultiIndex keys Mar 4, 2021
@maurolacy
Copy link
Contributor Author

Closing as a duplicate of #232.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant