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

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.

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

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::new_ip4(Qualifier::Pass, ip);
 assert_eq!(ip_mechanism.raw(), "192.168.11.0/24");
 assert_eq!(ip_mechanism.kind().is_ip(), true);
👎 Deprecated since 0.2.0:

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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Create a Mechanism from the provided string.

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

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:

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

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.