decon_spf

Struct SpfBuilder

Source
pub struct SpfBuilder { /* private fields */ }
Available on crate feature builder only.
Expand description

The definition of the SpfBuilder struct which contains all information related a single SPF record.

Implementations§

Source§

impl SpfBuilder

Source

pub fn new() -> Self

Create a new empty SpfBuilder struct.

Source

pub fn set_v1(&mut self) -> &mut Self

Set version to v=spf1

Source§

impl SpfBuilder

Source

pub fn set_v2_pra(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/pra

Source

pub fn set_v2_mfrom(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/mfrom

Source

pub fn set_v2_pra_mfrom(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/pra,mfrom

Source

pub fn set_v2_mfrom_pra(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/mfrom,pra

Source

pub fn is_v2(&self) -> bool

Available on crate feature spf2 only.

Check that version is v2

Source§

impl SpfBuilder

Source

pub fn version(&self) -> &String

Access the version attribute

Source

pub fn clear_mechanism(&mut self, kind: Kind)

Clear the passed Kind which has been passed. Sets the passed mechanism to None

§Note:

This method clears all associated Mechanism for the Kind provided.

§Example:
use decon_spf::mechanism::{Qualifier, Kind, Mechanism};
use decon_spf::SpfBuilder;
let mut spf = SpfBuilder::new();
spf.set_v1();
spf.append_mechanism(Mechanism::all_with_qualifier(Qualifier::Pass));
spf.append_mechanism(Mechanism::a(Qualifier::Pass));
spf.append_mechanism(Mechanism::ip(Qualifier::Pass,
                                                 "203.32.160.0/23".parse().unwrap()));
// Remove ip4 Mechanism
spf.clear_mechanism(Kind::IpV4);
Source

pub fn append_mechanism<T>(&mut self, mechanism: Mechanism<T>) -> &mut Self
where Self: Append<T>,

use decon_spf::mechanism::{Qualifier, Mechanism};
use decon_spf::SpfBuilder;
let mut spf = SpfBuilder::new();
spf.set_v1();
spf.append_mechanism(Mechanism::redirect(Qualifier::Pass,
                                "_spf.example.com").unwrap())
   .append_mechanism(Mechanism::all_with_qualifier(Qualifier::Pass));
assert!(spf.all().is_none());
§Note

When Redirect is present, All will be set to None.

Source

pub fn is_redirect(&self) -> bool

True if there is a redirect present in the spf record.

Source

pub fn redirect(&self) -> Option<&Mechanism<String>>

Returns a reference to the Redirect Mechanism

Source

pub fn includes(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to the a Vec of Mechanism<String> for Include

Source

pub fn a(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to a Vec of Mechanism<String> for A

Source

pub fn mx(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to a Vec of Mechanism<String> for MX

Source

pub fn ip4(&self) -> Option<&Vec<Mechanism<IpNetwork>>>

Returns a reference to a Vec of Mechanism<IpNetwork> for IP4

Source

pub fn ip6(&self) -> Option<&Vec<Mechanism<IpNetwork>>>

Returns a reference to a Vec of Mechanism<IpNetwork> for IP6

Source

pub fn exists(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to a Vec of Mechanism<String> for Exists

Source

pub fn ptr(&self) -> Option<&Mechanism<String>>

Returns a reference to a Vec of Mechanism<String> for Ptr

Source

pub fn all(&self) -> Option<&Mechanism<All>>

Returns a reference to Mechanism<All> for All

Source

pub fn build(self) -> Result<Spf<String>, SpfError>

Creates a Spf<String> from SpfBuilder

Source§

impl SpfBuilder

Source

pub fn iter(&self) -> SpfBuilderIterator

Allows you to iterate over Mechanisms contained within the SPF record.

§Note: Version string is not included.

Trait Implementations§

Source§

impl Clone for SpfBuilder

Source§

fn clone(&self) -> SpfBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpfBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpfBuilder

Source§

fn default() -> SpfBuilder

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SpfBuilder

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for SpfBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Spf<String>> for SpfBuilder

Converts a Spf<String> into a SpfBuilder`struct.

Source§

fn from(source: Spf<String>) -> Self

Converts to this type from the input type.
Source§

impl FromStr for SpfBuilder

Creates an SpfBuilder struct by parsing a string representation of Spf.

§Examples:

 use decon_spf::SpfBuilder;
 use decon_spf::SpfError;
 // Successful
 let input = "v=spf1 a mx -all";
 let spf: SpfBuilder = input.parse().unwrap();
 assert_eq!(spf.to_string(), input);

 // Additional Space between `A` and `MX`
 let invalid_input = "v=spf1 a   mx -all";
 let err: SpfError = invalid_input.parse::<SpfBuilder>().unwrap_err();
 assert_eq!(err, SpfError::WhiteSpaceSyntaxError);
 //  err.to_string() -> "Spf contains two or more consecutive whitespace characters.");
Source§

type Err = SpfError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for SpfBuilder

Source§

fn eq(&self, other: &SpfBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SpfBuilder

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SpfBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,