MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / decode_drawing

Function decode_drawing

canvas/src/decoding.rs:1659–1681  ·  view source on GitHub ↗

Decodes a canvas drawing represented as an iterator of characters. If there's an error in the stream, it will be the last item decoded.

(source: In)

Source from the content-addressed store, hash-verified

1657/// be the last item decoded.
1658///
1659pub fn decode_drawing<In: IntoIterator<Item=char>>(source: In) -> impl Iterator<Item=Result<Draw, DecoderError>> {
1660 // The decoder represents the state machine used for decoding this item
1661 let mut decoder = CanvasDecoder::new();
1662 let mut seen_error = false;
1663
1664 // Map the source characters into draw actions via the decoder
1665 source.into_iter()
1666 .filter_map(move |chr| {
1667 match decoder.decode(chr) {
1668 Ok(Some(draw)) => Some(Ok(draw)),
1669 Ok(None) => None,
1670 Err(err) => {
1671 // The decoder will just return errors once it hits a failure: only return the initial error
1672 if !seen_error {
1673 seen_error = true;
1674 Some(Err(err))
1675 } else {
1676 None
1677 }
1678 }
1679 }
1680 })
1681}
1682
1683///
1684/// Error from either a decoder or the stream that's feeding it

Callers 5

check_round_tripFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 1

decodeMethod · 0.80

Tested by

no test coverage detected