Skip to main content

find_contract

Function find_contract 

pub fn find_contract<'t, T>(
    table: &'t [(&'static str, T)],
    method: &str,
    route: &str,
) -> Option<&'t T>
Expand description

The row a call belongs to: an RPC route is its op_id (or batch); a REST route is bound as the template, and keyed "<METHOD> <template>". No allocation: an RPC id never starts with a method and a space. A HEAD is the GET op’s (axum serves it from that route; the binding still names the method it was sent with).

use cratestack_core::find_contract;

let table = [("model.Widget.list", 1), ("GET /widgets/{id}", 2)];
assert_eq!(find_contract(&table, "POST", "model.Widget.list"), Some(&1));
assert_eq!(find_contract(&table, "GET", "/widgets/{id}"), Some(&2));
assert_eq!(find_contract(&table, "HEAD", "/widgets/{id}"), Some(&2));
assert_eq!(find_contract(&table, "DELETE", "/widgets/{id}"), None);