mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-12-18 14:06:37 +00:00
Implement TryFrom instead of TryInto
This commit is contained in:
parent
2aa2c9a642
commit
ed0f2fb593
1 changed files with 6 additions and 6 deletions
|
@ -8,7 +8,7 @@ use chrono::Utc;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use sqlx::{PgPool, Postgres, Transaction};
|
use sqlx::{PgPool, Postgres, Transaction};
|
||||||
use std::convert::TryInto;
|
use std::convert::{TryFrom, TryInto};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
|
@ -17,13 +17,13 @@ pub struct FormData {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<NewSubscriber> for FormData {
|
impl TryFrom<FormData> for NewSubscriber {
|
||||||
type Error = String;
|
type Error = String;
|
||||||
|
|
||||||
fn try_into(self) -> Result<NewSubscriber, Self::Error> {
|
fn try_from(value: FormData) -> Result<Self, Self::Error> {
|
||||||
let name = SubscriberName::parse(self.name)?;
|
let name = SubscriberName::parse(value.name)?;
|
||||||
let email = SubscriberEmail::parse(self.email)?;
|
let email = SubscriberEmail::parse(value.email)?;
|
||||||
Ok(NewSubscriber { email, name })
|
Ok(Self { email, name })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue