Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Group functions and structs together
Browse files Browse the repository at this point in the history
  • Loading branch information
0rzech committed Mar 13, 2024
1 parent 7cbafc9 commit 80660c8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/routes/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,6 @@ async fn send_confirmation_email(
})
}

#[derive(Deserialize)]
struct FormData {
name: String,
email: String,
}

impl TryFrom<FormData> for NewSubscriber {
type Error = String;

fn try_from(value: FormData) -> Result<Self, Self::Error> {
let email = SubscriberEmail::parse(value.email)?;
let name = SubscriberName::parse(value.name)?;
Ok(NewSubscriber { email, name })
}
}

#[tracing::instrument(
name = "Storing subscription token in the database",
skip(transaction, subscription_token)
Expand All @@ -240,6 +224,22 @@ async fn store_token(
Ok(())
}

#[derive(Deserialize)]
struct FormData {
name: String,
email: String,
}

impl TryFrom<FormData> for NewSubscriber {
type Error = String;

fn try_from(value: FormData) -> Result<Self, Self::Error> {
let email = SubscriberEmail::parse(value.email)?;
let name = SubscriberName::parse(value.name)?;
Ok(NewSubscriber { email, name })
}
}

#[derive(Template)]
#[template(path = "welcome.html")]
struct HtmlBodyTemplate<'a> {
Expand Down

0 comments on commit 80660c8

Please sign in to comment.