Standardize Card to String conversion to use UTF-8 suit symbols#7
Standardize Card to String conversion to use UTF-8 suit symbols#7pashadia wants to merge 3 commits intoNydauron:masterfrom
Conversation
Nydauron
left a comment
There was a problem hiding this comment.
I like the addition.
The one thing I didn't realize about Display is that it implicitly implements the trait ToString. So, there are two different string conversion methods, the other one being:
playing-cards/src/core/card.rs
Lines 333 to 337 in 51adfa4
which prints out an alpha character for the suit rather than a symbol. My intentions with Display were to provide a prettified way of displaying the cards while also giving another the option to convert the Card (unaware of ToString). Seeing that there doesn't seem to be a way to override the blanket implementation, I guess it is best to also change From<Card> to just use to_string() (same inconsistency issue applies to From<Suit> for char).
If those changes could be made, alongside adding some additional documentation to Suit::from_char() referencing the ability to parse symbols, I think the PR would be good to merge.
|
I've made those changes, with the following exception:
That's incorrect. |
|
The inconsistency I was referring to was that let suit = Suit::Heart;
assert_eq!(suit.into::<char>(), '♥');
assert_eq!(suit.to_string(), "♥"); |
|
Ok, that's doable, but are you sure you want that? I think that having some way in which the structs would return an alphanumeric char/string could be beneficial for testing and rapid prototyping purposes. |
This will allow the
Cards to be parsed back from their.to_string()output.