mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2025-01-05 14:49:01 +00:00
Implement TryFrom instead of TryInto.
This commit is contained in:
parent
65761098ff
commit
12a7953777
1 changed files with 6 additions and 6 deletions
|
@ -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<NewSubscriber> for FormData {
|
||||
impl TryFrom<FormData> for NewSubscriber {
|
||||
type Error = String;
|
||||
|
||||
fn try_into(self) -> Result<NewSubscriber, Self::Error> {
|
||||
let name = SubscriberName::parse(self.name)?;
|
||||
let email = SubscriberEmail::parse(self.email)?;
|
||||
Ok(NewSubscriber { email, name })
|
||||
fn try_from(value: FormData) -> Result<Self, Self::Error> {
|
||||
let name = SubscriberName::parse(value.name)?;
|
||||
let email = SubscriberEmail::parse(value.email)?;
|
||||
Ok(Self { email, name })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue