PropsBuilder: use from trait

This commit is contained in:
veeso 2021-03-06 20:15:23 +01:00
parent 5c9cb7eece
commit db0c54b781
4 changed files with 10 additions and 13 deletions

View file

@ -201,7 +201,7 @@ impl Component for FileList {
/// This returns a prop builder in order to make easier to create
/// new properties for the element.
fn get_props(&self) -> PropsBuilder {
PropsBuilder::from_props(&self.props)
PropsBuilder::from(self.props.clone())
}
/// ### on

View file

@ -214,7 +214,7 @@ impl Component for Input {
/// This returns a prop builder in order to make easier to create
/// new properties for the element.
fn get_props(&self) -> PropsBuilder {
PropsBuilder::from_props(&self.props)
PropsBuilder::from(self.props.clone())
}
/// ### on

View file

@ -180,7 +180,7 @@ impl Component for RadioGroup {
/// This returns a prop builder in order to make easier to create
/// new properties for the element.
fn get_props(&self) -> PropsBuilder {
PropsBuilder::from_props(&self.props)
PropsBuilder::from(self.props.clone())
}
/// ### on

View file

@ -95,15 +95,6 @@ pub struct PropsBuilder {
}
impl PropsBuilder {
/// ### from_props
///
/// Create a props builder from existing properties
pub fn from_props(props: &Props) -> Self {
PropsBuilder {
props: Some(props.clone()),
}
}
/// ### build
///
/// Build Props from builder
@ -222,6 +213,12 @@ impl PropsBuilder {
}
}
impl From<Props> for PropsBuilder {
fn from(props: Props) -> Self {
PropsBuilder { props: Some(props) }
}
}
impl Default for PropsBuilder {
fn default() -> Self {
PropsBuilder {
@ -413,7 +410,7 @@ mod tests {
))
.build();
// Ok, now make a builder from properties
let builder: PropsBuilder = PropsBuilder::from_props(&props);
let builder: PropsBuilder = PropsBuilder::from(props);
assert!(builder.props.is_some());
}