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),
}

--
Simon Sapin
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to