Le vendredi 20 septembre 2013 11:52:14 Simon Sapin a écrit :
> Le 13/09/2013 23:03, Simon Sapin a écrit :
> > /// Takes the invalid byte sequence.
> > /// Return a replacement string, or None to abort with a DecodeError.
> > condition! {
> > 
> >       pub decoding_error : ~[u8] -> Option<~str>;
> > 
> > }
> > 
> > /// Functions to be used with decoding_error::cond.trap
> > mod decoding_error_handlers {
> > 
> >       fn fatal(_: ~[u8]) -> Option<~str> { None }
> >       fn replacement(_: ~[u8]) -> Option<~str> { Some(~"\uFFFD") }
> > 
> > }
> 
> Allocating ~"\uFFFD" repeatedly is, let’s say, unfortunate. This could
> be avoided by having the return value be:
> 
> enum DecodingErrorResult {
>      AbortDecoding,
>      ReplacementString(~str),
>      ReplacementChar(char),
> }
> 
> Similarly, for encoding:
> 
> enum EncodingErrorResult {
>      AbortDecoding,
>      ReplacamentByteSequence(~[u8]),
>      ReplacementByte(u8),
> }

That's a nice addition, it's even better this way !

I have one more question regarding the error handling : in DecodeError, what 
does 'input_byte_offset' mean ? Is it relative to the 'invalid_byte_sequence' 
or to the beginning of the decoded stream ?
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to