diff --git a/src/admin/domain.rs b/src/admin/domain.rs index 826662a..f9134ca 100644 --- a/src/admin/domain.rs +++ b/src/admin/domain.rs @@ -143,7 +143,7 @@ pub mod repository { } #[derive(Debug, Serialize)] - struct Field { + pub struct Field { widget: String, label: Option, #[serde(rename = "type")] @@ -301,8 +301,9 @@ pub mod repository { self } - // set field for a given key. - pub fn set_widget(mut self, name: &str, widget: Widget) -> Self { + pub fn set_widget>(mut self, name: &str, item: T) -> Self { + let field = item.into(); // Convert the input into a Field + // Find the index of the existing entry with the same name, if it exists let pos = self .fields @@ -311,12 +312,10 @@ pub mod repository { match pos { Some(index) => { - // If found, replace the `Field` part of the tuple - self.fields[index].1 = Field::from(widget); + self.fields[index].1 = field; } None => { - // If not found, add a new entry - self.fields.push((name.to_owned(), Field::from(widget))); + self.fields.push((name.to_owned(), field)); } } self