diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2022-07-12 11:31:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 11:31:29 +0200 |
commit | cf521aaf60414f613a77a64ddd7fe60361641e54 (patch) | |
tree | a05291ec71df87106437d23cbf90d82a1aae71bd /src | |
parent | f983651759bc3712a41f0a462bc5affdb45a0990 (diff) |
Refactor match session name (#1582)
Diffstat (limited to 'src')
-rw-r--r-- | src/sessions.rs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/sessions.rs b/src/sessions.rs index fc42b610b..616596efd 100644 --- a/src/sessions.rs +++ b/src/sessions.rs @@ -151,24 +151,23 @@ pub enum SessionNameMatch { } pub(crate) fn match_session_name(prefix: &str) -> Result<SessionNameMatch, io::ErrorKind> { - return match get_sessions() { - Ok(sessions) => Ok({ - let filtered_sessions: Vec<String> = sessions - .iter() - .filter(|s| s.starts_with(prefix)) - .cloned() - .collect(); - if filtered_sessions.iter().any(|s| s == prefix) { - return Ok(SessionNameMatch::Exact(prefix.to_string())); - } - match &filtered_sessions[..] { - [] => SessionNameMatch::None, - [s] => SessionNameMatch::UniquePrefix(s.to_string()), - _ => SessionNameMatch::AmbiguousPrefix(filtered_sessions), - } - }), - Err(e) => Err(e), - }; + let sessions = get_sessions()?; + + let filtered_sessions: Vec<_> = sessions.iter().filter(|s| s.starts_with(prefix)).collect(); + + if filtered_sessions.iter().any(|s| *s == prefix) { + return Ok(SessionNameMatch::Exact(prefix.to_string())); + } + + Ok({ + match &filtered_sessions[..] { + [] => SessionNameMatch::None, + [s] => SessionNameMatch::UniquePrefix(s.to_string()), + _ => { + SessionNameMatch::AmbiguousPrefix(filtered_sessions.into_iter().cloned().collect()) + }, + } + }) } pub(crate) fn session_exists(name: &str) -> Result<bool, io::ErrorKind> { |