Explorar o código

rust: Refactor Rust impl of protover_list_supports_protocol_or_later().

This includes a subtle difference in behaviour, as in 4258f1e18, where we return
(matching the C impl's return behaviour) earlier than before if parsing failed,
saving us computation in parsing the versions into a
protover::protoset::ProtoSet.

 * REFACTOR `protover::ffi::protover_list_supports_protocol_or_later()` to use
   new types and methods.
Isis Lovecruft %!s(int64=6) %!d(string=hai) anos
pai
achega
0a5494b81d
Modificáronse 1 ficheiros con 8 adicións e 6 borrados
  1. 8 6
      src/rust/protover/ffi.rs

+ 8 - 6
src/rust/protover/ffi.rs

@@ -138,13 +138,15 @@ pub extern "C" fn protocol_list_supports_protocol_or_later(
         Err(_) => return 0,
     };
 
-    let is_supported = protover_string_supports_protocol_or_later(
-        protocol_list,
-        protocol,
-        version,
-    );
+    let proto_entry: UnvalidatedProtoEntry = match protocol_list.parse() {
+        Ok(n)  => n,
+        Err(_) => return 1,
+    };
 
-    return if is_supported { 1 } else { 0 };
+    if proto_entry.supports_protocol_or_later(&protocol.into(), &version) {
+        return 1;
+    }
+    0
 }
 
 /// Provide an interface for C to translate arguments and return types for