Comment

Comment by vidarh

It seems the author might be unaware of the semantic difference expected for to_s vs. to_str and equivalent for other short vs long named conversions.

The former is expected to be pretty imprecise. E.g. if an object can somehow he described with a string it's ok to implement to_s.

But you should only implement to_str if an object can be naturally represented as a String. E.g. if you implement a specialized string class, implementing to_str is fine, while your Person class might reasonably return a persons name from to_s but probably shouldn't implement to_str.

parent vidarh 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton