Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::io::Cursor;
- // Should check if reading $cur for $length results in a slice equal to one of expected$
- macro_rules! matches_header (
- ( $cur:expr, $length:expr, $( $expected:expr), *) => {
- {
- use std::io::Read;
- let mut buf = [0;$length];
- match $cur.read(&mut buf) {
- $(
- Ok(_) if buf == $expected => true,
- )*
- _ => false
- }
- }
- };
- );
- fn main() {
- let mut cur = Cursor::new([71, 73, 70, 56, 57, 97]);
- if matches_header!(cur, 6, [71, 73, 70, 56, 55, 97], [71, 73, 70, 56, 57, 97]) {
- println!("Yes!")
- } else {
- println!("No!")
- }
- }
Add Comment
Please, Sign In to add comment