add put_code/{1,2}, get_code/{1,2}, improve get_* predicates

This commit is contained in:
Mark Thom
2020-05-05 22:42:35 -06:00
parent 47e3a5e75a
commit 414acda9e0
5 changed files with 340 additions and 88 deletions

View File

@@ -30,6 +30,15 @@ impl StreamType {
StreamType::Text => "text_stream",
}
}
#[inline]
pub(crate)
fn other(self) -> StreamType {
match self {
StreamType::Binary => StreamType::Text,
StreamType::Text => StreamType::Binary,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -662,7 +671,7 @@ impl MachineState {
} else if input.is_none() && stream.is_input_stream() {
Some("stream") // 8.14.2.3 g)
} else if stream.options.stream_type != expected_type {
Some(expected_type.as_str()) // 8.14.2.3 h)
Some(expected_type.other().as_str()) // 8.14.2.3 h)
} else {
None
};