Serde Email

A validating email type that can be serialised using Serde (and Sea Orm).

[![crate](https://img.shields.io/crates/v/serde-email.svg)](https://crates.io/crates/serde-email) [![docs](https://docs.rs/serde-email/badge.svg)](https://docs.rs/serde-email)

Introduction

This crate is for creating Email objects.

(Note this library will not check if the Email address exists. It only validates that it looks correct.)

Features

Usage

Building your own email addresses

```rust use ::serde_email::Email;

let email = Email::from_str("test@example.com").expect("A valid email address"); ```

Validating the email address yourself

```rust use ::serdeemail::isvalid_email;

if isvalidemail(&"test@example.com") { // do something } ```

Serialisation / Deserialisation

```rust use ::serdeemail::Email; use ::serdejson;

struct Person { name: String, email: Email, }

// Some JSON input data as a &str. Maybe this comes from the user. let data = r#" { "name": "John Doe", "email": "john@example.com" }"#;

// Parse the string of data into serdejson::Value. let person: Person = serdejson::from_str(data).unwrap();

// Access parts of the data by indexing with square brackets. println!("Hello {} I'll email you are {}", person.name, person.email); ```

Sea Orm Entities

You can use the Email type with Sea Orm, including using it to save data to the DB. Underneath it will serialise to a Text type within the DB.

```rust use ::seaorm::entity::prelude::*; use ::serde::Deserialize; use ::serde::Serialize; use ::serdeemail::Email;

[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]

[seaorm(tablename = "user")]

pub struct Model { #[seaorm(primarykey)] pub id: i32, pub email: Email, // use as an email field }

[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {} ```

Special Thanks

The validation is all done by the email_address crate.