Struct decon_spf::mechanism::Mechanism [−][src]
pub struct Mechanism<T> { /* fields omitted */ }
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 softfail
check mechanism is neutral
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 since 0.2.0: This will be removed in a future release. Use to_string() which is implemented through Display trait.
This will be removed in a future release. Use to_string() which is implemented through Display trait.
Rebuild and return the string representation of the given 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.to_string(), "?a");
let mechanism_a_string = Mechanism::new_a_with_mechanism(Qualifier::Pass,
String::from("example.com"));
assert_eq!(mechanism_a_string.to_string(), "a:example.com");
👎 Deprecated since 0.2.0: This will be removed in a future release. Use to_string() which is implemented through Display trait.
This will be removed in a future release. Use to_string() which is implemented through Display trait.
Returns the mechanism string representation of an IP4/6 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::new_ip4(Qualifier::Pass, ip);
assert_eq!(ip_mechanism.to_string(), "ip4:192.168.11.0/24");
assert_eq!(ip_mechanism.as_network(), &ip);
Returns the mechanism as an IpNetwork
Trait Implementations
Create a Mechanism
Examples:
use decon_spf::mechanism::Mechanism;
let a: Mechanism<String> = "a".parse().unwrap();
assert_eq!(a.kind().is_a(), true);
let mx = "mx".parse::<Mechanism<String>>().unwrap();
assert_eq!(mx.kind().is_mx(), true);
let mx2 = "-mx:example.com".parse::<Mechanism<String>>().unwrap();
assert_eq!(mx2.qualifier().is_fail(), true);
assert_eq!(mx2.to_string(), "-mx:example.com");
Create a Mechanism
Examples:
use decon_spf::mechanism::MechanismError;
use decon_spf::mechanism::Mechanism;
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_ip6: Result<Mechanism<IpNetwork>, MechanismError> = "ip6:203.32.160.0/24".parse();
let err = ip6_but_ip6.unwrap_err();
assert_eq!(err, MechanismError::NotIP6Network("203.32.160.0/24".to_string()));
assert_eq!(err.to_string(), "Was given ip6:203.32.160.0/24. This 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