-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add borrow!/borrow? ... [as ...]
syntax
#164
Comments
From the issue it appears we would like to implement the following syntax to borrow a reference to an object in storage:
The above seems to imply that the downcast to the My understanding is that Thinking through this, I think it makes sense to have
and the force-unwrapped version:
Mainly because otherwise, Now if we want to support the above however, speaking with Bastian, it seems unlikely anyone would want just an
Or perhaps we always force-unwrap the object reference, by definition, and just have the following which is semantically the same:
Would love feedback! Trying to determine a rational syntax that is internally consistent with the existing |
Going to put this on pause for a bit as it is a lower prority and Dete is away next week -- would love to get his input on this. |
Assigning this to Tim to re-assign out. |
As you're updating To avoid doing this: var collectionRef = getAccount(address).getCapability(/public/CollectionOne)!
.borrow<&{Contract.Collection}>()
if collectionRef == nil {
collectionRef = getAccount(address).getCapability(/public/CollectionTwo)!
.borrow<&{Contract.Collection}>()
}
if collectionRef == nil {
collectionRef = getAccount(address).getCapability(/public/CollectionThree)!
.borrow<&{Contract.Collection}>()
} We could do this: var collectionRef = getAccount(address).getCapability(/public/*)!
.borrow<&{Contract.Collection}>() This might be linked to #208 |
Capabilities are a security measure so specifying which one is to be used seems like something that should be explicit. And a wildcard should return all matches, not just the first one. That said, combining Storage Querying API #208 with Typed Paths #369 would allow the program to find if any capabilities of a given type exist under a given path and to use just the first one if desired. I'm wary of recommending a pattern rather than a feature but I think making this explicit in this way might make the program's intent clearer. |
Hey @robmyers, sorry for not making this more clear. I meant I expect Dapps to move NFTs around as they see fit and not necessarily put them back to the path from where they took them from. Example:
I agree with making things explicit, but from another angle, To make an analogy, imagine on your Mac you need to search for a PDF file, you don't remember the name of it, so it's just |
Reject resources-methods being used as function-pointers
No progress in a long time, closing for now. Please open a new issue if you still feel like this should exist |
Context
It was suggested that in addition/instead of
borrow<T>()
function calls,the dedicated syntax
borrow!/borrow? ... [as ...]
might be more readable and explicit.Definition of Done
The text was updated successfully, but these errors were encountered: