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

Expose APIs to conditionally construct Interface instances #209

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Dec 8, 2020

Use this interface to:

  • Implement a string_debug protocol for HashSet and HashMap.
  • Implement the eq protocol for HashSet (HashMap can't be
    implemented yet, because Value comparisons for it are not available).

This means that you can now correctly debug format an instance of HashMap and HashSet, even though they are external types:

use std::collections::HashMap;

struct Foo;

pub fn main() {
    let m = HashMap::new();
    m.insert(0, true);
    m.insert(1, Foo);
    dbg(m);
}

Correctly prints:

{0: true, 1: Foo}

Furethermore, HashSet (and soon HashMap) can not be checked for equality:

use std::collections::HashSet;

pub fn main() {
    let a = HashSet::new();
    let b = HashSet::new();
    b.insert(10);
    assert_eq!(a, b);
}

image

Note: due to limitations, we currently have to use a temporary buffer in the fmt::Debug impl of Value. This can be fixed by making the debug formatting more explicit.

Use this interface to:
* Implement a `string_debug` protocol for `HashSet` and `HashMap`.
* Implement the `eq` protocol for `HashSet` (`HashMap` can't be
  implemented yet, because `Value` comparisons for it are not available).
@udoprog udoprog added the enhancement New feature or request label Dec 8, 2020
@udoprog udoprog merged commit d5a914d into main Dec 8, 2020
@udoprog udoprog deleted the expose-interface branch December 8, 2020 19:06
@udoprog udoprog added the changelog Issue has been added to the changelog label Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant