#[derive(Debug, Clone)]
#[must_use]
pub struct RenderResult<T> {
pub output: T,
pub warnings: Vec<String>,
}
impl<T> RenderResult<T> {
pub fn new(output: T) -> Self {
Self {
output,
warnings: Vec::new(),
}
}
pub fn with_warnings(output: T, warnings: Vec<String>) -> Self {
Self { output, warnings }
}
pub fn has_warnings(&self) -> bool {
!self.warnings.is_empty()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_has_no_warnings() {
let result = RenderResult::new("hello");
assert_eq!(result.output, "hello");
assert!(result.warnings.is_empty());
assert!(!result.has_warnings());
}
#[test]
fn test_with_warnings() {
let result = RenderResult::with_warnings("output", vec!["warning 1".to_string()]);
assert_eq!(result.output, "output");
assert_eq!(result.warnings.len(), 1);
assert!(result.has_warnings());
}
#[test]
fn test_with_empty_warnings() {
let result = RenderResult::with_warnings(42, Vec::new());
assert_eq!(result.output, 42);
assert!(!result.has_warnings());
}
}