nom_locate icon indicating copy to clipboard operation
nom_locate copied to clipboard

Remove copy from Display implementation

Open ThePerkinrex opened this issue 3 years ago • 2 comments

Removes possible allocation, removing to_string.

Maybe this is not allowed, as it is a possible breaking change, as every T: Display implements ToString but not the other way around.

I thought it may be positive to note that the old implementation allocated when not needed, like when LocatedSpan<&str> is used

ThePerkinrex avatar Jan 08 '22 14:01 ThePerkinrex

Hmm, interesting. Sadly, https://github.com/rust-lang/rust/issues/31844 isn't stable yet, so we can't have both; and adding a cfg feature seems overkill (and doesn't really solve the problem since both can't be used in the same application).

Do you know any type that implements ToString but not Display?

progval avatar Jan 08 '22 14:01 progval

Not in std, but anyone could create it, in a dependent crate, for example.

That would mean that if somebody did that, which isn't recommended, and I think clippy advises against it, but it is possible, they would have a breaking change when updating.

Anyways, this isn't much, as I think not many people would use display on this type directly, but it could be something to note, to add it to the next breaking release (v4.0.0)

I just wanted to let you know of this

ThePerkinrex avatar Jan 08 '22 15:01 ThePerkinrex