#![deny(
clippy::all,
clippy::cargo,
clippy::nursery,
clippy::pedantic,
deprecated_in_future,
future_incompatible,
missing_docs,
nonstandard_style,
rust_2018_idioms,
rustdoc,
warnings,
unused_results,
unused_qualifications,
unused_lifetimes,
unused_import_braces,
unsafe_code,
unreachable_pub,
trivial_casts,
trivial_numeric_casts,
missing_debug_implementations,
missing_copy_implementations
)]
#![warn(variant_size_differences)]
#![allow(clippy::multiple_crate_versions, missing_doc_code_examples)]
#![doc(html_root_url = "https://docs.rs/automaat-processor-print-output/0.1.0")]
use automaat_core::{Context, Processor};
use serde::{Deserialize, Serialize};
use std::{error, fmt};
#[cfg_attr(feature = "juniper", derive(juniper::GraphQLObject))]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct PrintOutput {
pub output: String,
}
#[cfg(feature = "juniper")]
#[cfg_attr(feature = "juniper", derive(juniper::GraphQLInputObject))]
#[graphql(name = "PrintOutputInput")]
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Input {
output: String,
}
#[cfg(feature = "juniper")]
impl From<Input> for PrintOutput {
fn from(input: Input) -> Self {
Self {
output: input.output,
}
}
}
impl<'a> Processor<'a> for PrintOutput {
const NAME: &'static str = "Print Output";
type Error = Void;
type Output = String;
fn run(&self, _context: &Context) -> Result<Option<Self::Output>, Self::Error> {
let output = match self.output.as_ref() {
"" => None,
string => Some(string.to_owned()),
};
Ok(output)
}
}
#[derive(Clone, Copy, Debug)]
#[allow(clippy::empty_enum)]
pub enum Void {}
impl fmt::Display for Void {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {}
}
}
impl error::Error for Void {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {}
}
}
#[cfg(test)]
mod tests {
use super::*;
mod run {
use super::*;
#[test]
fn empty_output() {
let processor = PrintOutput {
output: "".to_owned(),
};
let context = Context::new().unwrap();
let output = processor.run(&context).unwrap();
assert!(output.is_none())
}
#[test]
fn string_output() {
let processor = PrintOutput {
output: "hello".to_owned(),
};
let context = Context::new().unwrap();
let output = processor.run(&context).unwrap();
assert_eq!(output, Some("hello".to_owned()))
}
}
mod validate {
use super::*;
#[test]
fn empty_output() {
let processor = PrintOutput {
output: "".to_owned(),
};
processor.validate().unwrap()
}
#[test]
fn string_output() {
let processor = PrintOutput {
output: "hello".to_owned(),
};
processor.validate().unwrap()
}
}
#[test]
fn test_readme_deps() {
version_sync::assert_markdown_deps_updated!("README.md");
}
#[test]
fn test_html_root_url() {
version_sync::assert_html_root_url_updated!("src/lib.rs");
}
}