Lift a `:::ref{to= edge=}` leaf into a typed reference edge. Both `to` and `edge` are required (a ref with no target or no edge type is a lift error), and `edge` must be a known *ref* edge: a dependency edge (`depends`/ `blockedBy`), review/remediation edge, or an evidence-bearing explicit implementation declaration. Edges like `verifiedBy`/`about` are rejected even though they are valid edges els
(d: &Directive)
| 286 | /// implementation declaration. Edges like |
| 287 | /// `verifiedBy`/`about` are rejected even though they are valid edges elsewhere. |
| 288 | fn lift_ref(d: &Directive) -> Result<Ref> { |
| 289 | let to = d |
| 290 | .attr("to") |
| 291 | .ok_or_else(|| CanonicalError::Lift("':::ref' is missing required 'to'".into()))? |
| 292 | .to_string(); |
| 293 | let edge = d |
| 294 | .attr("edge") |
| 295 | .ok_or_else(|| CanonicalError::Lift("':::ref' is missing required 'edge'".into()))? |
| 296 | .to_string(); |
| 297 | if !vocab::is_known_ref_edge(&edge) { |
| 298 | return Err(CanonicalError::Lift(format!( |
| 299 | "':::ref' edge '{edge}' is not a valid ref edge (dependency {:?}, remediation {:?}, review {:?}, or implementation {:?})", |
| 300 | vocab::DEPENDENCY_EDGES, |
| 301 | vocab::REMEDIATION_EDGES, |
| 302 | vocab::REVIEW_EDGES, |
| 303 | vocab::IMPLEMENTATION_EDGES |
| 304 | ))); |
| 305 | } |
| 306 | let declaration_evidence = d.attr("declarationEvidence").map(str::to_owned); |
| 307 | if edge == "declaresImplementation" |
| 308 | && (!vocab::is_canonical_change_iri(&to) |
| 309 | || declaration_evidence |
| 310 | .as_deref() |
| 311 | .is_none_or(|e| e.trim().is_empty())) |
| 312 | { |
| 313 | return Err(CanonicalError::Lift("implementation declarations require a canonical full-hash change IRI and nonempty declarationEvidence".into())); |
| 314 | } |
| 315 | Ok(Ref { |
| 316 | type_: d.id.as_ref().map(|_| NodeType::Ref.as_str().to_string()), |
| 317 | id: d.id.as_ref().map(|id| as_urn("ref", id)), |
| 318 | to, |
| 319 | edge, |
| 320 | declaration_evidence, |
| 321 | }) |
| 322 | } |
| 323 | |
| 324 | /// Wrap a local id into `urn:atomic:<kind>:<local>` unless already a urn. |
| 325 | fn as_urn(kind: &str, local: &str) -> String { |
no test coverage detected