stable-structures icon indicating copy to clipboard operation
stable-structures copied to clipboard

Structures API should support deref coercion

Open ufoscout opened this issue 4 months ago • 0 comments

The current API implementation does not support deref coercion like the standard Rust collections. In some cases, this forces a redundant instantiation only for retrieving data. E.g.:

    #[test]
    fn should_allow_retrieving_with_deref_types() {
        let mem = make_memory();
        let mut btree: BTreeMap<String, u64, _> = BTreeMap::new(mem.clone());
        btree.insert("foo".to_string(), 42);

        // This one works but it forces a useless instantiation of a new String
        assert_eq!(btree.get(&"foo".to_string()), Some(42)); // OK

        // This does not compile because the API strictly expects a `&String` type
        assert_eq!(btree.get("foo"), Some(42)); 
    }

ufoscout avatar Aug 29 '25 11:08 ufoscout