pub struct Mechanism<T> { /* private fields */ }
Expand description

Stores its Kind, Qualifier, and its Value

Implementations§

source§

impl<T> Mechanism<T>

These are the generic methods for the struct of Mechanism.
All the following methods can be used on any struct of type Mechanism.

source

pub fn is_pass(&self) -> bool

Check mechanism is pass

source

pub fn is_fail(&self) -> bool

check mechanism is fail

source

pub fn is_softfail(&self) -> bool

Check mechanism is softfail

source

pub fn is_neutral(&self) -> bool

Check mechanism is neutral

source

pub fn kind(&self) -> &Kind

Returns a reference to the Mechanism’s Kind

source

pub fn qualifier(&self) -> &Qualifier

Returns a reference to the Mechanism’s Qualifier

source

pub fn mechanism(&self) -> &Option<T>

Returns a reference to the Mechanism’s Value.
This could return a String, IpNetwork, or None

source§

impl Mechanism<String>

source

pub fn new_redirect(qualifier: Qualifier, mechanism: String) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use redirect() instead

Create a new Mechanism struct of Redirect

source

pub fn redirect( qualifier: Qualifier, rrdata: &str ) -> Result<Self, MechanismError>

Create a new Mechanism struct of Redirect

source

pub fn new_a_without_mechanism(qualifier: Qualifier) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use a() instead

Create a new Mechanism struct of A with no string value.

source

pub fn new_a_with_mechanism(qualifier: Qualifier, mechanism: String) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use a().with_rrdata() instead

Create a new Mechanism struct of A with string value.

source

pub fn a(qualifier: Qualifier) -> Self

Create a new Mechanism struct of A

Example:
use decon_spf::mechanism::Qualifier;
use decon_spf::mechanism::Mechanism;
// New `A` without rrdata.
let m = Mechanism::new_a_without_mechanism(Qualifier::Pass);
assert_eq!(m.kind().is_a(), true);
assert_eq!(m.raw(), "a".to_string());
assert_eq!(m.mechanism().is_none(), true);
// Create `A` with rrdata
if let Ok(m_with_rrdata) = Mechanism::a(Qualifier::Pass)
                                               .with_rrdata("example.com") {
  assert_eq!(m_with_rrdata.raw(), "example.com".to_string());
  assert_eq!(m_with_rrdata.to_string(), "a:example.com".to_string());
}
// Create `A` with bad rrdata and `strict-dns` is disabled
if let Ok(bad_rrdata) = Mechanism::a(Qualifier::Pass)
                                            .with_rrdata("example.xx") {
  assert_eq!(bad_rrdata.raw(), "example.xx".to_string());
  assert_eq!(bad_rrdata.to_string(), "a:example.xx".to_string());
}
// Create `A` with bad rrdata and `strict-dns` is enabled
if let Err(bad_rrdata) = Mechanism::a(Qualifier::Pass)
                                             .with_rrdata("example.xx") {
  assert_eq!(bad_rrdata, MechanismError::InvalidDomainHost("example.xx".to_string()));
}
source

pub fn new_mx_without_mechanism(qualifier: Qualifier) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use mx() instead

Create a new Mechanism struct of MX without string value.

source

pub fn new_mx_with_mechanism(qualifier: Qualifier, mechanism: String) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use mx().with_rrdata() instead

Create a new Mechanism struct of MX

source

pub fn mx(qualifier: Qualifier) -> Self

Create a new Mechanism struct of MX

Example:
use decon_spf::mechanism::Qualifier;
use decon_spf::mechanism::Mechanism;
// without rrdata
let mx = Mechanism::mx(Qualifier::Pass);
assert_eq!(mx.kind().is_mx(), true);
assert_eq!(mx.raw(), "mx");
// with rrdata
if let Ok(mx) = Mechanism::mx(Qualifier::Pass)
                              .with_rrdata("example.com") {
  assert_eq!(mx.kind().is_mx(), true);
  assert_eq!(mx.raw(), "example.com".to_string());
  assert_eq!(mx.to_string(), "mx:example.com".to_string());
}
source

pub fn new_include(qualifier: Qualifier, mechanism: String) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use include() instead

Create a new Mechanism struct of Include

source

pub fn include( qualifier: Qualifier, rrdata: &str ) -> Result<Self, MechanismError>

Create a new Mechanism struct of Include

Example:
use decon_spf::mechanism::Qualifier;
use decon_spf::mechanism::Mechanism;
let include = Mechanism::include(Qualifier::Pass,
                                        "example.com").unwrap();
assert_eq!(include.qualifier().as_str(), "");
assert_eq!(include.raw(), "example.com");
assert_eq!(include.to_string(), "include:example.com");
let include2 = Mechanism::include(Qualifier::SoftFail,
                                         "example.com").unwrap();
assert_eq!(include2.to_string(), "~include:example.com")
source

pub fn new_ptr_without_mechanism(qualifier: Qualifier) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use ptr() instead

Create a new Mechanism struct of Ptr with no value

source

pub fn new_ptr_with_mechanism(qualifier: Qualifier, mechanism: String) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use ptr().with_rrdata() instead

Create a new Mechanism struct of Ptr

source

pub fn ptr(qualifier: Qualifier) -> Self

Create a new Mechanism struct of Ptr

Example:
use decon_spf::mechanism::Qualifier;
use decon_spf::mechanism::Mechanism;
// without rrdata
let ptr = Mechanism::ptr(Qualifier::Fail);
assert_eq!(ptr.to_string(), "-ptr");
// with rrdata
let ptr = Mechanism::ptr(Qualifier::Fail)
                                .with_rrdata("example.com").unwrap();
assert_eq!(ptr.to_string(), "-ptr:example.com");
source

pub fn new_exists(qualifier: Qualifier, mechanism: String) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use exists().with_rrdata() instead

Create a new Mechanism struct of Exists

source

pub fn exists( qualifier: Qualifier, rrdata: &str ) -> Result<Self, MechanismError>

Create a new Mechanism struct of Exists

source

pub fn with_rrdata( self, rrdata: impl Into<String> ) -> Result<Self, MechanismError>

Set the rrdata for Mechanism

Note: This is only applicable for Mechanisms of A, MX and Ptr.

All other Mechanism types require rrdata to be set. That is to say that rrdata is optional for A, MX and PTR
See: a for an example.

source

pub fn new_all(qualifier: Qualifier) -> Self

👎Deprecated: This will be depreciated in 0.3.0. Please use all() instead

Create a new Mechanism struct of All

source

pub fn all(qualifier: Qualifier) -> Self

Create a new Mechanism struct of All

source

pub fn raw(&self) -> String

Return the mechanism string stored in the Mechanism

Example:
use decon_spf::mechanism::Qualifier;
use decon_spf::mechanism::Mechanism;
let mechanism_a = Mechanism::new_a_without_mechanism(Qualifier::Neutral);
assert_eq!(mechanism_a.raw(), "a");
let mechanism_a_string = Mechanism::new_a_with_mechanism(Qualifier::Neutral,
                                                         String::from("example.com"));
assert_eq!(mechanism_a_string.raw(), "example.com");
source§

impl Mechanism<IpNetwork>

source

pub fn new_ip( qualifier: Qualifier, mechanism: IpNetwork ) -> Mechanism<IpNetwork>

👎Deprecated: This will be depreciated in 0.3.0. Please use ip() instead

Create a new V4 or V6 Mechanism<IpNetwork>

source

pub fn ip_from_string( string: &str ) -> Result<Mechanism<IpNetwork>, MechanismError>

Create a new V4 or V6 Mechanism from a string representation.

 let string = "+ip4:203.32.160.0/24";
 if let Ok(m) = Mechanism::ip_from_string(&string) {
   assert_eq!(m.raw(), "203.32.160.0/24");
   assert_eq!(m.to_string(), "ip4:203.32.160.0/24");
 }
source

pub fn ip(qualifier: Qualifier, rrdata: IpNetwork) -> Mechanism<IpNetwork>

Create a new V4 or V6 Mechanism<IpNetwork> Will correctly set its kind based on the IpNetwork type.

Examples:
use decon_spf::mechanism::{Mechanism, Qualifier};

// Requires: use ipnetwork::IpNetwork;
let ip: IpNetwork = "192.168.11.0/24".parse().unwrap();
let mechanism = Mechanism::ip(Qualifier::Pass, ip);
assert_eq!(mechanism.kind().is_ip_v4(), true);
assert_eq!(mechanism.raw(), "192.168.11.0/24".to_string());
assert_eq!(mechanism.as_network().to_string(), "192.168.11.0/24".to_string());
assert_eq!(mechanism.as_network().prefix(), 24);

// This section does not require use of ipnetwork::IpNetwork;
let mechanism_ip4 = Mechanism::ip(Qualifier::Pass,
                                      "203.32.160.0/23".parse().unwrap());
assert_eq!(mechanism_ip4.kind().is_ip(), true);
assert_eq!(mechanism_ip4.kind().is_ip_v4(), true);
assert_eq!(mechanism_ip4.to_string(), "ip4:203.32.160.0/23".to_string());
let mechanism_ip6 = Mechanism::ip(Qualifier::Pass,
                                      "2001:4860:4000::/36".parse().unwrap());
assert_eq!(mechanism_ip6.kind().is_ip(), true);
assert_eq!(mechanism_ip6.kind().is_ip_v6(),true);
assert_eq!(mechanism_ip6.to_string(), "ip6:2001:4860:4000::/36".to_string());
source

pub fn raw(&self) -> String

Returns the simple string representation of the mechanism

Example
 use ipnetwork::IpNetwork;
 use decon_spf::mechanism::Qualifier;
 use decon_spf::mechanism::Mechanism;
 let ip: IpNetwork = "192.168.11.0/24".parse().unwrap();
 let ip_mechanism = Mechanism::ip(Qualifier::Pass, ip);
 assert_eq!(ip_mechanism.raw(), "192.168.11.0/24");
 assert_eq!(ip_mechanism.kind().is_ip(), true);
source

pub fn as_network(&self) -> &IpNetwork

Returns a reference to the mechanism as an IpNetwork

Trait Implementations§

source§

impl<T: Clone> Clone for Mechanism<T>

source§

fn clone(&self) -> Mechanism<T>

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<T: Debug> Debug for Mechanism<T>

source§

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

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

impl<T: Default> Default for Mechanism<T>

source§

fn default() -> Mechanism<T>

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

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

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 Mechanism<IpNetwork>

Provide to_string for Mechanism<IpNetwork>

source§

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

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

impl Display for Mechanism<String>

Provide to_string for Mechanism<String>

source§

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

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

impl FromStr for Mechanism<IpNetwork>

Create a Mechanism<IpNetwork> from the provided string.

Examples:

 let ip4: Mechanism<IpNetwork> = "ip4:203.32.160.0/24".parse().unwrap();
 assert_eq!(ip4.kind().is_ip_v4(), true);

 let ip6 = "ip6:2001:4860:4000::/36".parse::<Mechanism<IpNetwork>>().unwrap();
 assert_eq!(ip6.kind().is_ip_v6(), true);

 let bad_ip4: Result<Mechanism<IpNetwork>, MechanismError> = "ip4:203.32.160.0/33".parse();
 assert_eq!(bad_ip4.unwrap_err().to_string(), "invalid address: 203.32.160.0/33");

 let ip6_but_ip4: Result<Mechanism<IpNetwork>, MechanismError> = "ip6:203.32.160.0/24".parse();
 let err = ip6_but_ip4.unwrap_err();
 assert_eq!(err, MechanismError::NotIP6Network("203.32.160.0/24".to_string()));
 assert_eq!(err.to_string(), "203.32.160.0/24 is not an ip6 network");
§

type Err = MechanismError

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

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

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

impl FromStr for Mechanism<String>

Create a Mechanism<String> from the provided string.

Examples:

 let a: Mechanism<String> = "a".parse().unwrap();
 assert_eq!(a.kind().is_a(), true);

 if let Ok(mx) = "mx".parse::<Mechanism<String>>() {
   assert_eq!(mx.kind().is_mx(), true);
 }
 if let Ok(mx2) = "-mx:example.com".parse::<Mechanism<String>>() {
   assert_eq!(mx2.qualifier().is_fail(), true);
   assert_eq!(mx2.to_string(), "-mx:example.com");
 }
§

type Err = MechanismError

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

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

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

impl<T: PartialEq> PartialEq for Mechanism<T>

source§

fn eq(&self, other: &Mechanism<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for Mechanism<T>
where T: Serialize,

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 TryFrom<&str> for Mechanism<IpNetwork>

§

type Error = MechanismError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&str> for Mechanism<String>

§

type Error = MechanismError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T> StructuralPartialEq for Mechanism<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Mechanism<T>
where T: RefUnwindSafe,

§

impl<T> Send for Mechanism<T>
where T: Send,

§

impl<T> Sync for Mechanism<T>
where T: Sync,

§

impl<T> Unpin for Mechanism<T>
where T: Unpin,

§

impl<T> UnwindSafe for Mechanism<T>
where T: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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>,