Prechádzať zdrojové kódy

implement deref for FormValue

Evan Almloff 1 rok pred
rodič
commit
a20a85dad6
1 zmenil súbory, kde vykonal 11 pridanie a 0 odobranie
  1. 11 0
      packages/html/src/events/form.rs

+ 11 - 0
packages/html/src/events/form.rs

@@ -1,5 +1,6 @@
 use crate::file_data::FileEngine;
 use crate::file_data::HasFileData;
+use std::ops::Deref;
 use std::{collections::HashMap, fmt::Debug};
 
 use dioxus_core::Event;
@@ -18,6 +19,7 @@ pub enum FormValue {
     Text(String),
     VecText(Vec<String>),
 }
+
 impl From<FormValue> for Vec<String> {
     fn from(value: FormValue) -> Self {
         match value {
@@ -26,6 +28,15 @@ impl From<FormValue> for Vec<String> {
         }
     }
 }
+
+impl Deref for FormValue {
+    type Target = [String];
+
+    fn deref(&self) -> &Self::Target {
+        self.as_slice()
+    }
+}
+
 impl FormValue {
     /// Convenient way to represent Value as slice
     pub fn as_slice(&self) -> &[String] {