From 177c9e8bfa87aab3d483990c333c4fe4e2646dd2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 3 Jul 2024 23:12:43 +0000 Subject: [PATCH] add split_once_infallible string util Signed-off-by: Jason Volk --- src/core/utils/string.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/utils/string.rs b/src/core/utils/string.rs index 84a928a0..78765154 100644 --- a/src/core/utils/string.rs +++ b/src/core/utils/string.rs @@ -1,5 +1,13 @@ use crate::Result; +pub const EMPTY: &str = ""; + +#[inline] +#[must_use] +pub fn split_once_infallible<'a>(input: &'a str, delim: &'_ str) -> (&'a str, &'a str) { + input.split_once(delim).unwrap_or((input, EMPTY)) +} + /// Parses the bytes into a string. #[inline] pub fn string_from_bytes(bytes: &[u8]) -> Result {