lifthrasiir / rust-encoding

Character encoding support for Rust
MIT License
284 stars 59 forks source link

Provide access to the underlying container of writers in the common case #108

Open hsivonen opened 7 years ago

hsivonen commented 7 years ago

(As discussed on IRC many weeks ago.)

When StringWriter is a String, provide access to the String. When ByteWriter is a Vec<u8>, provide access to the Vec<u8>.

This allows converters that write directly to a slice without virtual method calls inside the conversion loop to work without an intermediate copy in the common case (i.e. with the default trait implementations) while not breaking compatibility with custom implementations of the traits. (And by giving access to the whole container object rather than just a slice, this allow the converter to tell the container to grow appropriately.)