Prior to this change, the IntoString trait and its into_string method implemented to specify a string representation used a String'iso argument and were required to return the String'iso at the end. This used to be necessary to ensure that the final built string could remain isolated, and thus be sendable or made immutable. However, it caused extra burden on the implementation.
Now, that method takes a String'ref as the argument and returns None.
To obtain a String'iso, the caller can use the String.take_buffer method to extract the underlying buffer and lift it to an iso. This does not allocate a new underlying buffer and does not copy the data, so there is no copy cost to pay. The only cost is allocating the throwaway String wrapper object, but this is small (always 4 words) and in many cases can be potentially lifted to a stack allocation at the LLVM level, so there shouldn't be much performance downside to worry about
The builtin implementation of composed string literals (a.k.a. interpolated strings) does this take_buffer lift implicitly, so that such string literals will continue to return as String'iso.
The Inspect.into method (and the corresponding inspect_into method that some types may choose to implement) have been changed in the same way (now using String'ref instead of String'iso), and the same comments above apply to this other case of the same pattern shift.
Prior to this change, the
IntoString
trait and itsinto_string
method implemented to specify a string representation used aString'iso
argument and were required to return theString'iso
at the end. This used to be necessary to ensure that the final built string could remain isolated, and thus be sendable or made immutable. However, it caused extra burden on the implementation.Now, that method takes a
String'ref
as the argument and returnsNone
.To obtain a
String'iso
, the caller can use theString.take_buffer
method to extract the underlying buffer and lift it to aniso
. This does not allocate a new underlying buffer and does not copy the data, so there is no copy cost to pay. The only cost is allocating the throwawayString
wrapper object, but this is small (always 4 words) and in many cases can be potentially lifted to a stack allocation at the LLVM level, so there shouldn't be much performance downside to worry aboutThe builtin implementation of composed string literals (a.k.a. interpolated strings) does this
take_buffer
lift implicitly, so that such string literals will continue to return asString'iso
.The
Inspect.into
method (and the correspondinginspect_into
method that some types may choose to implement) have been changed in the same way (now usingString'ref
instead ofString'iso
), and the same comments above apply to this other case of the same pattern shift.