From 10e79d4bc7a85ff28ffbcfb1584c80bd5b796eae Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 27 Jan 2023 14:52:38 +0000 Subject: Shorten create_and_open_dir error handling --- src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 73cd9b0..6f68c22 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,13 +15,11 @@ fn create_and_open_dir + Copy>( d: &Dir, path: P, ) -> std::io::Result { - match d.create_dir(path) { - Ok(()) => Ok(()), - Err(e) => match e.kind() { - ErrorKind::AlreadyExists => Ok(()), - _ => Err(e), - }, - }?; + if let Err(e) = d.create_dir(path) { + if e.kind() != ErrorKind::AlreadyExists { + return Err(e); + } + } d.open_dir(path) } -- cgit v1.2.3-54-g00ecf