MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / optional_not_found

Function optional_not_found

atomic-audit/src/substantive/branching.rs:126–154  ·  view source on GitHub ↗
(
    pattern: Node<'_>,
    value: Node<'_>,
    context: &mut Context<'_>,
)

Source from the content-addressed store, hash-verified

124}
125
126fn optional_not_found(
127 pattern: Node<'_>,
128 value: Node<'_>,
129 context: &mut Context<'_>,
130) -> Result<bool, &'static str> {
131 // A typed NotFound guard plus an absent optional value is an explicit
132 // absence contract, not an unexplained catch-all success fallback.
133 if context.compact(value)? != "Ok(None)" {
134 return Ok(false);
135 }
136 let pattern = context.compact(pattern)?;
137 let Some(rest) = pattern.strip_prefix("Err(") else {
138 return Ok(false);
139 };
140 let Some((binding, guard)) = rest.split_once(")if") else {
141 return Ok(false);
142 };
143 if binding.is_empty()
144 || !binding
145 .chars()
146 .all(|c| c.is_ascii_alphanumeric() || c == '_')
147 {
148 return Ok(false);
149 }
150 Ok(
151 guard == format!("{binding}.kind()==std::io::ErrorKind::NotFound")
152 || guard == format!("std::io::ErrorKind::NotFound=={binding}.kind()"),
153 )
154}

Callers 1

inspectFunction · 0.85

Calls 3

compactMethod · 0.80
is_emptyMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected