Skip to content

el_key - alpha version #356

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

Closed
wants to merge 1 commit into from
Closed

Conversation

MartinKavik
Copy link
Member

#354

 circle![
    el_key(&key),   // key implements ToString
    attrs![
        At::Cx => 15.0 + x,
        At::Cy => 15.0 + y,

@David-OConnor
Copy link
Member

I like the API

@MartinKavik
Copy link
Member Author

MartinKavik commented Feb 17, 2020

API is consistent with the el_ref but it should only require PartialEq instead of ToString.
I chose ToString because String implements Debug & Clone and we don't have to add another generic parameter to El and adapt the entire codebase to it.

/// WIP
/// - it doesn't patch elements with the different keys, BUT it replace the old element with the new one.
/// - `key` restriction (have to implements `ToString`) will be probably relaxed in the future.
pub fn el_key(key: &impl ToString) -> ElKey {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be Display instead? Citing docs:

This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn't be implemented directly: Display should be implemented instead, and you get the ToString implementation for free.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know this advice. I don't implement ToString, I'm just using impl instead of generics here.
I think - if I understand that advice correctly - that ToString is basically something like a subset of Display. So I chose to write &impl ToString because it sounds to me a little bit more relaxed than Display. And I don't want to "display" the key anywhere, I just want to convert it to String so it feels also more descriptive to me.

@MartinKavik
Copy link
Member Author

Closing in favor of #357 (that PR is based on this one)

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

Successfully merging this pull request may close these issues.

3 participants