pub struct Mechanism<T> { /* private fields */ }
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 softfail
Check mechanism is neutral
👎 Deprecated: This will be depreciated in 0.3.0. Please use redirect()
instead
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
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
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
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
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
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
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
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
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
This will be depreciated in 0.3.0. Please use all()
instead
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
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
Provide to_string for Mechanism
Provide to_string for Mechanism
Create a Mechanism
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");
}
Create a Mechanism
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");
Auto Trait Implementations
impl<T> RefUnwindSafe for Mechanism<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Mechanism<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more