From 12a7953777f99e93afe6aaf7484b9ebfa1bbe405 Mon Sep 17 00:00:00 2001 From: Luca Palmieri Date: Wed, 1 Sep 2021 09:22:31 +0200 Subject: [PATCH] Implement TryFrom instead of TryInto. --- src/routes/subscriptions.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/subscriptions.rs b/src/routes/subscriptions.rs index 1c977a1..b540123 100644 --- a/src/routes/subscriptions.rs +++ b/src/routes/subscriptions.rs @@ -2,7 +2,7 @@ use crate::domain::{NewSubscriber, SubscriberEmail, SubscriberName}; use actix_web::{web, HttpResponse}; use chrono::Utc; use sqlx::PgPool; -use std::convert::TryInto; +use std::convert::{TryFrom, TryInto}; use uuid::Uuid; #[derive(serde::Deserialize)] @@ -11,13 +11,13 @@ pub struct FormData { name: String, } -impl TryInto for FormData { +impl TryFrom for NewSubscriber { type Error = String; - fn try_into(self) -> Result { - let name = SubscriberName::parse(self.name)?; - let email = SubscriberEmail::parse(self.email)?; - Ok(NewSubscriber { email, name }) + fn try_from(value: FormData) -> Result { + let name = SubscriberName::parse(value.name)?; + let email = SubscriberEmail::parse(value.email)?; + Ok(Self { email, name }) } }