Struct trust_dns::rr::domain::Name
[−]
[src]
pub struct Name { /* fields omitted */ }
TODO: all Names should be stored in a global "intern" space, and then everything that uses them should be through references. As a workaround the Strings are all Rc as well as the array TODO: Currently this probably doesn't support binary names, it would be nice to do that.
Methods
impl Name
[src]
fn new() -> Self
Create a new domain::Name, i.e. label
fn root() -> Self
Returns the root label, i.e. no labels, can probably make this better in the future.
fn is_root(&self) -> bool
Returns true if there are no labels, i.e. it's empty.
In DNS the root is represented by .
Examples
use trust_dns::rr::domain::Name; let root = Name::root(); assert_eq!(&root.to_string(), ".");
fn is_fqdn(&self) -> bool
Returns true if the name is a fully qualified domain name.
If this is true, it has effects like only querying for this single name, as opposed to building up a search list in resolvers.
warning: this interface is unstable and may change in the future
Examples
use std::str::FromStr; use trust_dns::rr::domain::Name; let name = Name::from_str("www").unwrap(); assert!(!name.is_fqdn()); let name = Name::from_str("www.example.com").unwrap(); assert!(!name.is_fqdn()); let name = Name::from_str("www.example.com.").unwrap(); assert!(name.is_fqdn());
fn set_fqdn(&mut self, val: bool)
Specifies this name is a fully qualified domain name
warning: this interface is unstable and may change in the future
fn label(self, label: &'static str) -> Self
inline builder
see: append_label
for replacement
fn append_label<S: Into<String>>(self, label: S) -> Self
Appends the label to the end of this name
Example
use std::str::FromStr; use trust_dns::rr::domain::Name; let name = Name::from_str("www.example").unwrap(); let name = name.append_label("com"); assert_eq!(name, Name::from_str("www.example.com").unwrap());
fn from_labels<S: Into<String>>(labels: Vec<S>) -> Self
Creates a new Name from the specified labels
Arguments
labels
- vector of items which will be stored as Strings.
Examples
use std::str::FromStr; use trust_dns::rr::domain::Name; let from_labels = Name::from_labels(vec!["www", "example", "com"]); assert_eq!(from_labels, Name::from_str("www.example.com").unwrap()); let root = Name::from_labels::<String>(vec![]); assert!(root.is_root());
fn with_labels(labels: Vec<String>) -> Self
Deprecated in favor of from_labels
fn prepend_label(&self, label: Rc<String>) -> Self
Prepends the label to this Name, returning a new name
Carries forward is_fqdn from self.
no direct replacement, consider reordering prepends to conform with appends
fn add_label(&mut self, label: Rc<String>) -> &mut Self
appends the String to this label at the end
see: append_label
for replacement
fn append(&mut self, other: &Self) -> &mut Self
appends the other to this name
see: append_name
and append_domain
for replacements
fn append_name(self, other: &Self) -> Self
Appends other
to self
, returning a new Name
Carries forward is_fqdn
from other
.
Examples
use std::str::FromStr; use trust_dns::rr::domain::Name; let local = Name::from_str("www").unwrap(); let domain = Name::from_str("example.com").unwrap(); assert!(!domain.is_fqdn()); let name = local.clone().append_name(&domain); assert_eq!(name, Name::from_str("www.example.com").unwrap()); assert!(!name.is_fqdn()); // see also `Name::append_domain` let domain = Name::from_str("example.com.").unwrap(); assert!(domain.is_fqdn()); let name = local.append_name(&domain); assert_eq!(name, Name::from_str("www.example.com.").unwrap()); assert!(name.is_fqdn());
fn append_domain(self, domain: &Self) -> Self
Appends the domain
to self
, making the new Name an FQDN
This is an alias for append_name with the added effect of marking the new Name as a fully-qualified-domain-name.
Examples
use std::str::FromStr; use trust_dns::rr::domain::Name; let local = Name::from_str("www").unwrap(); let domain = Name::from_str("example.com").unwrap(); let name = local.append_domain(&domain); assert_eq!(name, Name::from_str("www.example.com").unwrap()); assert!(name.is_fqdn())
fn to_lowercase(&self) -> Self
Creates a new Name with all labels lowercased
Examples
use trust_dns::rr::domain::Name; use std::cmp::Ordering; let example_com = Name::from_labels(vec!["Example", "Com"]); assert_eq!(example_com.cmp_with_case(&Name::from_labels(vec!["example", "com"]), false), Ordering::Less); assert_eq!(example_com.to_lowercase().cmp_with_case(&Name::from_labels(vec!["example", "com"]), false), Ordering::Equal);
fn base_name(&self) -> Name
Trims off the first part of the name, to help with searching for the domain piece
Examples
use trust_dns::rr::domain::Name; let example_com = Name::from_labels(vec!["example", "com"]); assert_eq!(example_com.base_name(), Name::from_labels(vec!["com"])); assert_eq!(Name::from_labels(vec!["com"]).base_name(), Name::root()); assert_eq!(Name::root().base_name(), Name::root());
fn trim_to(&self, num_labels: usize) -> Name
Trims to the number of labels specified
Examples
use trust_dns::rr::domain::Name; let example_com = Name::from_labels(vec!["example", "com"]); assert_eq!(example_com.trim_to(2), Name::from_labels(vec!["example", "com"])); assert_eq!(example_com.trim_to(1), Name::from_labels(vec!["com"])); assert_eq!(example_com.trim_to(0), Name::root());
fn zone_of(&self, name: &Self) -> bool
returns true if the name components of self are all present at the end of name
Example
use trust_dns::rr::domain::Name; let name = Name::from_labels(vec!["www", "example", "com"]); let name = Name::from_labels(vec!["www", "example", "com"]); let zone = Name::from_labels(vec!["example", "com"]); let another = Name::from_labels(vec!["example", "net"]); assert!(zone.zone_of(&name)); assert!(!another.zone_of(&name));
fn num_labels(&self) -> u8
Returns the number of labels in the name, discounting *
.
Examples
use trust_dns::rr::domain::Name; let root = Name::root(); assert_eq!(root.num_labels(), 0); let example_com = Name::from_labels(vec!["example", "com"]); assert_eq!(example_com.num_labels(), 2); let star_example_com = Name::from_labels(vec!["*", "example", "com"]); assert_eq!(star_example_com.num_labels(), 2);
fn len(&self) -> usize
returns the length in bytes of the labels. '.' counts as 1
This can be used as an estimate, when serializing labels, they will often be compressed and/or escaped causing the exact length to be different.
fn parse(local: &str, origin: Option<&Self>) -> ParseResult<Self>
attempts to parse a name such as "example.com."
or "subdomain.example.com."
Examples
use trust_dns::rr::domain::Name; let name = Name::parse("example.com.", None).unwrap(); assert_eq!(name.base_name(), Name::from_labels(vec!["com"])); assert_eq!(*name[0], String::from("example"));
fn emit_as_canonical(
&self,
encoder: &mut BinEncoder,
canonical: bool
) -> EncodeResult
&self,
encoder: &mut BinEncoder,
canonical: bool
) -> EncodeResult
Emits the canonical version of the name to the encoder.
In canonical form, there will be no pointers written to the encoder (i.e. no compression).
fn emit_with_lowercase(
&self,
encoder: &mut BinEncoder,
lowercase: bool
) -> EncodeResult
&self,
encoder: &mut BinEncoder,
lowercase: bool
) -> EncodeResult
Writes the labels, as lower case, to the encoder
fn cmp_with_case(&self, other: &Self, ignore_case: bool) -> Ordering
compares with the other label, ignoring case
fn to_string(&self) -> String
Converts the Name labels to the String form.
This converts the name to an unescaped format, that could be used with parse. The name is
is followed by the final .
, e.g. as in www.example.com.
, which represents a fully
qualified Name.
Trait Implementations
impl Debug for Name
[src]
impl Eq for Name
[src]
impl Clone for Name
[src]
fn clone(&self) -> Name
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl From<IpAddr> for Name
[src]
impl From<Ipv4Addr> for Name
[src]
impl From<Ipv6Addr> for Name
[src]
impl Hash for Name
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq<Name> for Name
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl BinSerializable<Name> for Name
[src]
fn read(decoder: &mut BinDecoder) -> DecodeResult<Name>
parses the chain of labels this has a max of 255 octets, with each label being less than 63. all names will be stored lowercase internally. This will consume the portions of the Vec which it is reading...
fn emit(&self, encoder: &mut BinEncoder) -> EncodeResult
Write the type to the stream
impl Display for Name
[src]
impl Index<usize> for Name
[src]
type Output = String
The returned type after indexing
fn index<'a>(&'a self, _index: usize) -> &'a String
The method for the indexing (container[index]
) operation
impl PartialOrd<Name> for Name
[src]
fn partial_cmp(&self, other: &Name) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Name
[src]
fn cmp(&self, other: &Self) -> Ordering
RFC 4034 DNSSEC Resource Records March 2005
6.1. Canonical DNS Name Order
For the purposes of DNS security, owner names are ordered by treating
individual labels as unsigned left-justified octet strings. The
absence of a octet sorts before a zero value octet, and uppercase
US-ASCII letters are treated as if they were lowercase US-ASCII
letters.
To compute the canonical ordering of a set of DNS names, start by
sorting the names according to their most significant (rightmost)
labels. For names in which the most significant label is identical,
continue sorting according to their next most significant label, and
so forth.
For example, the following names are sorted in canonical DNS name
order. The most significant label is "example". At this level,
"example" sorts first, followed by names ending in "a.example", then
by names ending "z.example". The names within each level are sorted
in the same way.
example
a.example
yljkjljk.a.example
Z.a.example
zABC.a.EXAMPLE
z.example
\001.z.example
*.z.example
\200.z.example
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
ord_max_min
)Compares and returns the minimum of two values. Read more