Skip to main content

extract_method_string_extension

Function extract_method_string_extension 

Source
pub fn extract_method_string_extension(
    pool: &DescriptorPool,
    extension_fqn: &str,
) -> BTreeMap<String, String>
Expand description

Walk every method declared in pool, look for the MethodOptions-level extension named extension_fqn, and return a map keyed by response-message FQN (e.g. my.v1.Resource) with the extension’s string value.

Methods that don’t declare the extension are skipped silently. Multiple methods returning the same response type with different extension values: first encountered wins (per pool iteration order). Returning the same value from every method is the convention — mismatch is a service-author bug worth catching with a conformance test.

Returns an empty map when no methods declare the extension.

§Example

// Given a .proto with:
//   import "envelope/v1/conventions.proto";
//   service UserService {
//     rpc GetUser(GetUserRequest) returns (User) {
//       option (envelope.v1.etag_field) = "version";
//     }
//   }
let out = compile_protos(&["user.proto"], &[staged.path()])?;
let etag_fields = extract_method_string_extension(&out.pool, "envelope.v1.etag_field");
assert_eq!(etag_fields.get("my.v1.User"), Some(&"version".to_string()));