FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
https://docs.fuel.network/docs/sway/
Apache License 2.0
62.76k stars 5.36k forks source link

Glob import does not import StorageMap items #6499

Closed Braqzen closed 3 weeks ago

Braqzen commented 3 weeks ago

Forc 0.63.3

Given the import below, the method get() (and others) ought to be discoverable on the map. It is in the standard library but it does not find it.

library;

use std::storage::storage_map::*;

struct Queue {
    queue: StorageMap<u256, b256>,
}

impl Queue {
    fn dequeue(self, val: u256) {
        let v = self.queue.get(val);
    }
}

Error: No method named "get" found for type "StorageMap<u256, b256>".

bitzoic commented 3 weeks ago

This error is expected. StorageMap does not have the get() function implemented on Self.

get() is implemented on the StorageKey type: impl<K, V> StorageKey<StorageMap<K, V>>. https://github.com/FuelLabs/sway/blob/de242ad1e4d4cc2de98848a29c137cb8d36bc70c/sway-lib-std/src/storage/storage_map.sw#L18

Your struct should look like this:

struct Queue {
    queue: StorageKey<StorageMap<u256, b256>>,
}