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

Stores its Kind, Qualifier, and its Value

Implementations

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

Check mechanism is pass

check mechanism is fail

Check mechanism is softfail

Check mechanism is neutral

Returns a reference to the Mechanism’s Kind

Returns a reference to the Mechanism’s Qualifier

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

👎 Deprecated:

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

Create a new Mechanism struct of Redirect

Create a new Mechanism struct of Redirect

👎 Deprecated:

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

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

👎 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.

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()));
}
👎 Deprecated:

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

Create a new Mechanism struct of MX without string value.

👎 Deprecated:

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

Create a new Mechanism struct of MX

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());
}
👎 Deprecated:

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

Create a new Mechanism struct of Include

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")
👎 Deprecated:

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

Create a new Mechanism struct of Ptr with no value

👎 Deprecated:

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

Create a new Mechanism struct of Ptr

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");
👎 Deprecated:

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

Create a new Mechanism struct of Exists

Create a new Mechanism struct of Exists

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.

👎 Deprecated:

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

Create a new Mechanism struct of All

Create a new Mechanism struct of All

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");
👎 Deprecated:

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

Create a new V4 or V6 Mechanism

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");
 }

Create a new V4 or V6 Mechanism
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());

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);

Returns a reference to the mechanism as an IpNetwork

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Provide to_string for Mechanism

Formats the value using the given formatter. Read more

Provide to_string for Mechanism

Formats the value using the given formatter. Read more

Create a Mechanism 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");
 }

The associated error which can be returned from parsing.

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

Create a Mechanism 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");

The associated error which can be returned from parsing.

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.