From 6639bca976bab31f3429b348d7e755098240ab72 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 28 Mar 2023 15:06:28 -0700 Subject: [PATCH] Add new api for creating client When adding windows implementation the new_client call had a possibility of failing so the result was wrapped in a Result. This caused the existing api to use a unwrap_or_else and panic since we couldn't pass the result onto the user. Signed-off-by: James Sturtevant --- src/sync/client.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sync/client.rs b/src/sync/client.rs index 86ceb77..db57f68 100644 --- a/src/sync/client.rs +++ b/src/sync/client.rs @@ -50,10 +50,10 @@ impl Client { #[cfg(unix)] /// Initialize a new [`Client`] from raw file descriptor. + #[deprecated(since="0.8.0", note="please use `new_from_fd` instead")] pub fn new(fd: RawFd) -> Client { let conn = ClientConnection::new(fd); - // TODO: upgrade the API of Client::new and remove this panic for the major version release Self::new_client(conn).unwrap_or_else(|e| { panic!( "client was not successfully initialized: {}", e @@ -61,6 +61,14 @@ impl Client { }) } + #[cfg(unix)] + /// Initialize a new [`Client`] from raw file descriptor. + pub fn new_from_fd(fd: RawFd) -> Result { + let conn = ClientConnection::new(fd); + + Self::new_client(conn) + } + fn new_client(pipe_client: ClientConnection) -> Result { let client = Arc::new(pipe_client);