2
0
Эх сурвалжийг харах

Actually, forcibly unwrap a few call results that we _know_ to never return nil.

Daniel Alm 8 жил өмнө
parent
commit
f47347d2be

+ 5 - 6
Sources/gRPC/Handler.swift

@@ -38,24 +38,23 @@ public class Handler {
 
 
   /// The host name sent with the request
   /// The host name sent with the request
   public lazy var host: String? = {
   public lazy var host: String? = {
-    guard let string = cgrpc_handler_copy_host(self.underlyingHandler)
-      else { return nil }
+    // We actually know that this method will never return nil,
+    // so we can forcibly unwrap the result. (Also below.)
+    let string = cgrpc_handler_copy_host(self.underlyingHandler)!
     defer { cgrpc_free_copied_string(string) }
     defer { cgrpc_free_copied_string(string) }
     return String(cString: string, encoding: .utf8)
     return String(cString: string, encoding: .utf8)
   }()
   }()
 
 
   /// The method name sent with the request
   /// The method name sent with the request
   public lazy var method: String? = {
   public lazy var method: String? = {
-    guard let string = cgrpc_handler_copy_method(self.underlyingHandler)
-      else { return nil }
+    let string = cgrpc_handler_copy_method(self.underlyingHandler)!
     defer { cgrpc_free_copied_string(string) }
     defer { cgrpc_free_copied_string(string) }
     return String(cString: string, encoding: .utf8)
     return String(cString: string, encoding: .utf8)
   }()
   }()
 
 
   /// The caller address associated with the request
   /// The caller address associated with the request
   public lazy var caller: String? = {
   public lazy var caller: String? = {
-    guard let string = cgrpc_handler_call_peer(self.underlyingHandler)
-      else { return nil }
+    let string = cgrpc_handler_call_peer(self.underlyingHandler)!
     defer { cgrpc_free_copied_string(string) }
     defer { cgrpc_free_copied_string(string) }
     return String(cString: string, encoding: .utf8)
     return String(cString: string, encoding: .utf8)
   }()
   }()

+ 2 - 2
Sources/gRPC/OperationGroup.swift

@@ -164,8 +164,8 @@ class OperationGroup {
     for (i, operation) in operations.enumerated() {
     for (i, operation) in operations.enumerated() {
       switch operation {
       switch operation {
       case .receiveStatusOnClient:
       case .receiveStatusOnClient:
-        guard let string = cgrpc_observer_recv_status_on_client_copy_status_details(underlyingObservers[i])
-          else { return nil }
+        // We actually know that this method will never return nil, so we can forcibly the result. (Also below.)
+        let string = cgrpc_observer_recv_status_on_client_copy_status_details(underlyingObservers[i])!
         defer { cgrpc_free_copied_string(string) }
         defer { cgrpc_free_copied_string(string) }
         return String(cString: string, encoding: String.Encoding.utf8)
         return String(cString: string, encoding: String.Encoding.utf8)
       default:
       default: