cfn-guard 3.2.0

AWS CloudFormation Guard is an open-source general-purpose policy-as-code evaluation tool. It provides developers with a simple-to-use, yet powerful and expressive domain-specific language (DSL) to define policies and enables developers to validate JSON- or YAML- formatted structured data with those policies.
Documentation
use std::fs::File;
use std::io::{Cursor, Read, Stdin};

pub struct Reader {
    inner: ReadBuffer,
}

impl Default for Reader {
    fn default() -> Self {
        Self {
            inner: ReadBuffer::Stdin(std::io::stdin()),
        }
    }
}

impl Read for Reader {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        match &mut self.inner {
            ReadBuffer::Stdin(stdin) => stdin.read(buf),
            ReadBuffer::Cursor(cursor) => cursor.read(buf),
            ReadBuffer::File(file) => file.read(buf),
        }
    }
}

impl Reader {
    pub fn new(stdin: ReadBuffer) -> Self {
        Self { inner: stdin }
    }
}

pub enum ReadBuffer {
    Stdin(Stdin),
    Cursor(Cursor<Vec<u8>>),
    File(File),
}