chordsketch_core/
render_result.rs1#[derive(Debug, Clone)]
10#[must_use]
11pub struct RenderResult<T> {
12 pub output: T,
14 pub warnings: Vec<String>,
16}
17
18impl<T> RenderResult<T> {
19 pub fn new(output: T) -> Self {
21 Self {
22 output,
23 warnings: Vec::new(),
24 }
25 }
26
27 pub fn with_warnings(output: T, warnings: Vec<String>) -> Self {
29 Self { output, warnings }
30 }
31
32 #[must_use]
34 pub fn has_warnings(&self) -> bool {
35 !self.warnings.is_empty()
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn test_new_has_no_warnings() {
45 let result = RenderResult::new("hello");
46 assert_eq!(result.output, "hello");
47 assert!(result.warnings.is_empty());
48 assert!(!result.has_warnings());
49 }
50
51 #[test]
52 fn test_with_warnings() {
53 let result = RenderResult::with_warnings("output", vec!["warning 1".to_string()]);
54 assert_eq!(result.output, "output");
55 assert_eq!(result.warnings.len(), 1);
56 assert!(result.has_warnings());
57 }
58
59 #[test]
60 fn test_with_empty_warnings() {
61 let result = RenderResult::with_warnings(42, Vec::new());
62 assert_eq!(result.output, 42);
63 assert!(!result.has_warnings());
64 }
65}