rust-encoding
rust-encoding copied to clipboard
Add a "mid-level" API
Currently the API provides "high-level" and "low-level" methods. The former takes a single string/vector in memory with an error handling mechanism, and returns another string/vector:
fn decode(&'static Encoding, input: &[u8], trap: Trap) -> Result<~str,SendStr>;
The latter allows incremental processing of the input (eg. as it is downloaded from the network), but leaves error handling to the user:
fn decoder(&'static Encoding) -> ~Decoder;
fn raw_feed(&mut Decoder, input: &[u8], output: &mut StringWriter) -> (uint, Option<CodecError>);
fn raw_finish(&mut Decoder, output: &mut StringWriter) -> Option<CodecError>;
It would be useful to also have an intermediate that does error handling but allows incremental processing, eg:
fn decoder(&'static Encoding, trap: Trap) -> ~Decoder;
fn feed(&mut Decoder, input: &[u8], output: &mut StringWriter) -> Option<SendStr>;
fn finish(&mut Decoder, output: &mut StringWriter) -> Option<SendStr>;
(trap is part of the decoder, because there is no reason to change it mid-stream.)