(r: &Trace)
| 117 | } |
| 118 | |
| 119 | pub fn validate(r: &Trace) -> Result<()> { |
| 120 | validate_trace_id(&r.id)?; |
| 121 | let ident = ident_re(); |
| 122 | for (k, step) in &r.steps { |
| 123 | if !ident.is_match(k) { |
| 124 | return Err(TraceError::Validation(format!( |
| 125 | "step id `{}` invalid", |
| 126 | k |
| 127 | ))); |
| 128 | } |
| 129 | for fs in &step.from_steps { |
| 130 | if !r.steps.contains_key(fs) { |
| 131 | return Err(TraceError::Validation(format!( |
| 132 | "step `{}` references unknown step `{}`", |
| 133 | k, fs |
| 134 | ))); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | if has_cycle(r) { |
| 139 | return Err(TraceError::Validation( |
| 140 | "DAG cycle detected in from_steps".into(), |
| 141 | )); |
| 142 | } |
| 143 | Ok(()) |
| 144 | } |
| 145 | |
| 146 | fn has_cycle(r: &Trace) -> bool { |
| 147 | use std::collections::HashSet; |
searching dependent graphs…