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

Examples in the README do not compile #35

Open
chanced opened this issue Jun 22, 2023 · 0 comments
Open

Examples in the README do not compile #35

chanced opened this issue Jun 22, 2023 · 0 comments

Comments

@chanced
Copy link

chanced commented Jun 22, 2023

fn main() {
    use qp_trie::Trie;

    let mut trie = Trie::new();

    for i in 0u8..3 {
        for j in 0u8..3 {
            trie.insert([i, j], i + j);
        }
    }

    for i in 0u8..3 {
        trie.remove([1, i]);
    }

    assert!(trie.iter().all(|(&key, _)| key[0] != 1));
}
error[E0308]: mismatched types
   --> src/main.rs:13:21
    |
8   |             trie.insert([i, j], i + j);
    |                         ------  ----- this is of type `u8`, which causes `trie` to be inferred as `Trie<[u8; 2], u8>`
    |                         |
    |                         this is of type `[u8; 2]`, which causes `trie` to be inferred as `Trie<[u8; 2], u8>`
...
13  |         trie.remove([1, i]);
    |              ------ ^^^^^^
    |              |      |
    |              |      expected `&_`, found `[u8; 2]`
    |              |      help: consider borrowing here: `&[1, i]`
    |              arguments to this method are incorrect
    |
    = note: expected reference `&_`
                   found array `[u8; 2]`
note: method defined here
   --> /Users/chance/.cargo/registry/src/github.com-1ecc6299db9ec823/qp-trie-0.8.1/src/trie.rs:316:12
    |
316 |     pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
    |            ^^^^^^

For more information about this error, try `rustc --explain E0308`.

this one is fixed by referencing [1, i]:

-    trie.remove_prefix([1]);
+    trie.remove_prefix(&[1]);
fn main() {
    use qp_trie::Trie;

    let mut trie = Trie::new();

    for i in 0u8..3 {
        trie.extend((0u8..3).map(|j| ([i, j], i + j)));
    }

    trie.remove_prefix([1]);

    assert!(trie.iter().all(|(&key, _)| key[0] != 1));
}
error[E0308]: mismatched types
   --> src/main.rs:10:24
    |
7   |         trie.extend((0u8..3).map(|j| ([i, j], i + j)));
    |              ------ here the type of `trie` is inferred to be `Trie<[u8; 2], u8>`
...
10  |     trie.remove_prefix([1]);
    |          ------------- ^^^
    |          |             |
    |          |             expected `&_`, found `[{integer}; 1]`
    |          |             help: consider borrowing here: `&[1]`
    |          arguments to this method are incorrect
    |
    = note: expected reference `&_`
                   found array `[{integer}; 1]`
note: method defined here
   --> /Users/chance/.cargo/registry/src/github.com-1ecc6299db9ec823/qp-trie-0.8.1/src/trie.rs:330:12
    |
330 |     pub fn remove_prefix<Q: ?Sized>(&mut self, prefix: &Q) -> Trie<K, V>
    |            ^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
fn main() {
    use qp_trie::Trie;

    let mut trie = Trie::new();

    for i in 0u8..3 {
        trie.extend((0u8..3).map(|k| ([i, j], i + j)));
    }

    let mut iter = trie.iter_prefix([1]);

    assert_eq!(iter.next(), Some((&[1, 0], &1)));
    assert_eq!(iter.next(), Some((&[1, 1], &2)));
    assert_eq!(iter.next(), Some((&[1, 2], &3)));
    assert_eq!(iter.next(), None);
}
error[E0425]: cannot find value `j` in this scope
 --> src/main.rs:7:43
  |
7 |         trie.extend((0u8..3).map(|k| ([i, j], i + j)));
  |                                           ^ help: a local variable with a similar name exists: `i`

error[E0425]: cannot find value `j` in this scope
 --> src/main.rs:7:51
  |
7 |         trie.extend((0u8..3).map(|k| ([i, j], i + j)));
  |                                                   ^ help: a local variable with a similar name exists: `i`

error[E0308]: mismatched types
   --> src/main.rs:10:37
    |
10  |     let mut iter = trie.iter_prefix([1]);
    |                         ----------- ^^^
    |                         |           |
    |                         |           expected `&_`, found `[{integer}; 1]`
    |                         |           help: consider borrowing here: `&[1]`
    |                         arguments to this method are incorrect
    |
    = note: expected reference `&_`
                   found array `[{integer}; 1]`
note: method defined here
   --> /Users/chance/.cargo/registry/src/github.com-1ecc6299db9ec823/qp-trie-0.8.1/src/trie.rs:190:12
    |
190 |     pub fn iter_prefix<'a, Q: ?Sized>(&'a self, prefix: &Q) -> Iter<'a, K, V>
    |            ^^^^^^^^^^^

Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
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