From f833d95e79a1368eece29a53a00c3d8a9d927fbc Mon Sep 17 00:00:00 2001 From: serzhiio Date: Mon, 15 Jan 2024 17:16:44 +0400 Subject: [PATCH] Added useful methods --- packages/html/src/events/form.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/html/src/events/form.rs b/packages/html/src/events/form.rs index d22a5219f..4183326ae 100644 --- a/packages/html/src/events/form.rs +++ b/packages/html/src/events/form.rs @@ -18,6 +18,27 @@ pub enum FormValue { Text(String), VecText(Vec), } +impl Into> for FormValue { + fn into(self) -> Vec { + match self{ + FormValue::Text(s) => vec![s], + FormValue::VecText(vec) => vec, + } + } +} +impl FormValue { + /// Convenient way to represent Value as slice + pub fn as_slice(&self) -> &[String] { + match self{ + FormValue::Text(s) => std::slice::from_ref(s), + FormValue::VecText(vec) => vec.as_slice(), + } + } + /// Convert into Vec + pub fn to_vec(self) -> Vec { + self.into() + } +} /* DOMEvent: Send + SyncTarget relatedTarget */ pub struct FormData {