vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
// Substring first-match operation module.



// Backend-specific lowering marker.



// CPU reference kernel for `string_matching.substring_find_first`.

use crate::ops::string_matching::search_contract::{to_u32_offset, validate_search_inputs, MatchError, NOT_FOUND};

/// Return the first byte offset of `needle` in `haystack`, or [`NOT_FOUND`].
///
/// # Errors
///
/// Returns `Fix: ...` when either input exceeds the documented T47 cap.
pub fn substring_find_first(haystack: &[u8], needle: &[u8]) -> Result<u32, MatchError> {
    validate_search_inputs(haystack, needle)?;
    if needle.is_empty() {
        return Ok(0);
    }
    let Some(index) = haystack.windows(needle.len()).position(|window| window == needle) else {
        return Ok(NOT_FOUND);
    };
    to_u32_offset(index)
}