Struct trust_dns_proto::rr::domain::Name [−][src]
pub struct Name { /* fields omitted */ }
Them should be through references. As a workaround the Strings are all Rc as well as the array
Methods
impl Name
[src]
impl Name
pub fn new() -> Self
[src]
pub fn new() -> Self
Create a new domain::Name, i.e. label
pub fn root() -> Self
[src]
pub fn root() -> Self
Returns the root label, i.e. no labels, can probably make this better in the future.
pub fn is_root(&self) -> bool
[src]
pub 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_proto::rr::domain::Name; let root = Name::root(); assert_eq!(&root.to_string(), ".");
pub fn is_fqdn(&self) -> bool
[src]
pub 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_proto::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());
pub fn set_fqdn(&mut self, val: bool)
[src]
pub 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
pub fn iter(&self) -> LabelIter
[src]
pub fn iter(&self) -> LabelIter
Returns an iterator over the labels
pub fn append_label<L: IntoLabel>(self, label: L) -> ProtoResult<Self>
[src]
pub fn append_label<L: IntoLabel>(self, label: L) -> ProtoResult<Self>
Appends the label to the end of this name
Example
use std::str::FromStr; use trust_dns_proto::rr::domain::Name; let name = Name::from_str("www.example").unwrap(); let name = name.append_label("com").unwrap(); assert_eq!(name, Name::from_str("www.example.com").unwrap());
pub fn from_labels<I, L>(labels: I) -> ProtoResult<Self> where
I: IntoIterator<Item = L>,
L: IntoLabel,
[src]
pub fn from_labels<I, L>(labels: I) -> ProtoResult<Self> where
I: IntoIterator<Item = L>,
L: IntoLabel,
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_proto::rr::domain::Name; // From strings, uses utf8 conversion let from_labels = Name::from_labels(vec!["www", "example", "com"]).unwrap(); assert_eq!(from_labels, Name::from_str("www.example.com").unwrap()); // Force a set of bytes into labels (this is none-standard and potentially dangerous) let from_labels = Name::from_labels(vec!["bad chars".as_bytes(), "example".as_bytes(), "com".as_bytes()]).unwrap(); assert_eq!(from_labels[0].as_bytes(), "bad chars".as_bytes()); let root = Name::from_labels(Vec::<&str>::new()).unwrap(); assert!(root.is_root());
pub fn append_name(self, other: &Self) -> Self
[src]
pub 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_proto::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());
pub fn append_domain(self, domain: &Self) -> Self
[src]
pub 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_proto::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())
pub fn to_lowercase(&self) -> Self
[src]
pub fn to_lowercase(&self) -> Self
Creates a new Name with all labels lowercased
Examples
use std::cmp::Ordering; use std::str::FromStr; use trust_dns_proto::rr::domain::{Label, Name}; let example_com = Name::from_ascii("Example.Com").unwrap(); assert_eq!(example_com.cmp_case(&Name::from_str("example.com").unwrap()), Ordering::Less); assert!(example_com.to_lowercase().eq_case(&Name::from_str("example.com").unwrap()));
pub fn base_name(&self) -> Name
[src]
pub fn base_name(&self) -> Name
Trims off the first part of the name, to help with searching for the domain piece
Examples
use std::str::FromStr; use trust_dns_proto::rr::domain::Name; let example_com = Name::from_str("example.com.").unwrap(); assert_eq!(example_com.base_name(), Name::from_str("com.").unwrap()); assert_eq!(Name::from_str("com.").unwrap().base_name(), Name::root()); assert_eq!(Name::root().base_name(), Name::root());
pub fn trim_to(&self, num_labels: usize) -> Name
[src]
pub fn trim_to(&self, num_labels: usize) -> Name
Trims to the number of labels specified
Examples
use std::str::FromStr; use trust_dns_proto::rr::domain::Name; let example_com = Name::from_str("example.com.").unwrap(); assert_eq!(example_com.trim_to(2), Name::from_str("example.com.").unwrap()); assert_eq!(example_com.trim_to(1), Name::from_str("com.").unwrap()); assert_eq!(example_com.trim_to(0), Name::root()); assert_eq!(example_com.trim_to(3), Name::from_str("example.com.").unwrap());
pub fn zone_of_case(&self, name: &Self) -> bool
[src]
pub fn zone_of_case(&self, name: &Self) -> bool
same as zone_of allows for case sensitive call
pub fn zone_of(&self, name: &Self) -> bool
[src]
pub 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 std::str::FromStr; use trust_dns_proto::rr::domain::Name; let name = Name::from_str("www.example.com").unwrap(); let name = Name::from_str("www.example.com").unwrap(); let zone = Name::from_str("example.com").unwrap(); let another = Name::from_str("example.net").unwrap(); assert!(zone.zone_of(&name)); assert!(!name.zone_of(&zone)); assert!(!another.zone_of(&name));
pub fn num_labels(&self) -> u8
[src]
pub fn num_labels(&self) -> u8
Returns the number of labels in the name, discounting *
.
Examples
use std::str::FromStr; use trust_dns_proto::rr::domain::Name; let root = Name::root(); assert_eq!(root.num_labels(), 0); let example_com = Name::from_str("example.com").unwrap(); assert_eq!(example_com.num_labels(), 2); let star_example_com = Name::from_str("*.example.com.").unwrap(); assert_eq!(star_example_com.num_labels(), 2);
pub fn len(&self) -> usize
[src]
pub 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.
Examples
use std::str::FromStr; use trust_dns_proto::rr::domain::Name; assert_eq!(Name::from_str("www.example.com.").unwrap().len(), 16); assert_eq!(Name::from_str(".").unwrap().len(), 1); assert_eq!(Name::root().len(), 1);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns whether the length of the labels, in bytes is 0. In practive, since '.' counts as 1, this is never the case so the method returns false.
pub fn parse(local: &str, origin: Option<&Self>) -> ProtoResult<Self>
[src]
pub fn parse(local: &str, origin: Option<&Self>) -> ProtoResult<Self>
attempts to parse a name such as "example.com."
or "subdomain.example.com."
Examples
use std::str::FromStr; use trust_dns_proto::rr::domain::Name; let name = Name::from_str("example.com.").unwrap(); assert_eq!(name.base_name(), Name::from_str("com.").unwrap()); assert_eq!(name[0].to_string(), "example");
pub fn from_ascii<S: AsRef<str>>(name: S) -> ProtoResult<Self>
[src]
pub fn from_ascii<S: AsRef<str>>(name: S) -> ProtoResult<Self>
Will convert the string to a name only allowing ascii as valid input
This method will also preserve the case of the name where that's desirable
Examples
use trust_dns_proto::rr::Name; let bytes_name = Name::from_labels(vec!["WWW".as_bytes(), "example".as_bytes(), "COM".as_bytes()]).unwrap(); let ascii_name = Name::from_ascii("WWW.example.COM.").unwrap(); let lower_name = Name::from_ascii("www.example.com.").unwrap(); assert!(bytes_name.eq_case(&ascii_name)); assert!(!lower_name.eq_case(&ascii_name)); // escaped values let bytes_name = Name::from_labels(vec!["email.name".as_bytes(), "example".as_bytes(), "com".as_bytes()]).unwrap(); let name = Name::from_ascii("email\\.name.example.com.").unwrap(); assert_eq!(bytes_name, name); let bytes_name = Name::from_labels(vec!["bad.char".as_bytes(), "example".as_bytes(), "com".as_bytes()]).unwrap(); let name = Name::from_ascii("bad\\056char.example.com.").unwrap(); assert_eq!(bytes_name, name);
pub fn emit_as_canonical(
&self,
encoder: &mut BinEncoder,
canonical: bool
) -> ProtoResult<()>
[src]
pub fn emit_as_canonical(
&self,
encoder: &mut BinEncoder,
canonical: bool
) -> ProtoResult<()>
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).
pub fn emit_with_lowercase(
&self,
encoder: &mut BinEncoder,
lowercase: bool
) -> ProtoResult<()>
[src]
pub fn emit_with_lowercase(
&self,
encoder: &mut BinEncoder,
lowercase: bool
) -> ProtoResult<()>
Writes the labels, as lower case, to the encoder
Arguments
encoder
- encoder for writing this namelowercase
- if true the name will be lowercased, otherwise it will not be changed when writing
pub fn cmp_case(&self, other: &Self) -> Ordering
[src]
pub fn cmp_case(&self, other: &Self) -> Ordering
Case sensitive comparison
pub fn eq_case(&self, other: &Self) -> bool
[src]
pub fn eq_case(&self, other: &Self) -> bool
Compares the Names, in a case sensitive manner
pub fn to_ascii(&self) -> String
[src]
pub fn to_ascii(&self) -> String
Converts this name into an ascii safe string.
If the name is an IDNA name, then the name labels will be returned with the xn--
prefix.
see to_utf8
or the Display
impl for methods which convert labels to utf8.
pub fn to_utf8(&self) -> String
[src]
pub fn to_utf8(&self) -> String
Converts the Name labels to the utf8 String form.
This converts the name to an unescaped format, that could be used with parse. If, the name is
is followed by the final .
, e.g. as in www.example.com.
, which represents a fully
qualified Name.
pub fn is_localhost(&self) -> bool
[src]
pub fn is_localhost(&self) -> bool
Returns true if the Name
is either localhost or in the localhost zone.
Example
use std::str::FromStr; use trust_dns_proto::rr::Name; let name = Name::from_str("localhost").unwrap(); assert!(name.is_localhost()); let name = Name::from_str("localhost.").unwrap(); assert!(name.is_localhost()); let name = Name::from_str("my.localhost.").unwrap(); assert!(name.is_localhost());
Trait Implementations
impl Clone for Name
[src]
impl Clone for Name
fn clone(&self) -> Name
[src]
fn clone(&self) -> Name
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Default for Name
[src]
impl Default for Name
impl Debug for Name
[src]
impl Debug for Name
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Eq for Name
[src]
impl Eq for Name
impl Hash for Name
[src]
impl Hash for Name
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'a> IntoIterator for &'a Name
[src]
impl<'a> IntoIterator for &'a Name
type Item = &'a [u8]
The type of the elements being iterated over.
type IntoIter = LabelIter<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl From<IpAddr> for Name
[src]
impl From<IpAddr> for Name
impl From<Ipv4Addr> for Name
[src]
impl From<Ipv4Addr> for Name
impl From<Ipv6Addr> for Name
[src]
impl From<Ipv6Addr> for Name
impl PartialEq<Name> for Name
[src]
impl PartialEq<Name> for Name
fn eq(&self, other: &Self) -> bool
[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[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl BinEncodable for Name
[src]
impl BinEncodable for Name
fn emit(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
[src]
fn emit(&self, encoder: &mut BinEncoder) -> ProtoResult<()>
Write the type to the stream
fn to_bytes(&self) -> ProtoResult<Vec<u8>>
[src]
fn to_bytes(&self) -> ProtoResult<Vec<u8>>
Returns the object in binary form
impl<'r> BinDecodable<'r> for Name
[src]
impl<'r> BinDecodable<'r> for Name
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Name>
[src]
fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<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 from_bytes(bytes: &'r [u8]) -> ProtoResult<Self>
[src]
fn from_bytes(bytes: &'r [u8]) -> ProtoResult<Self>
Returns the object in binary form
impl Display for Name
[src]
impl Display for Name
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Index<usize> for Name
[src]
impl Index<usize> for Name
type Output = Label
The returned type after indexing.
fn index(&self, _index: usize) -> &Label
[src]
fn index(&self, _index: usize) -> &Label
Performs the indexing (container[index]
) operation.
impl PartialOrd<Name> for Name
[src]
impl PartialOrd<Name> for Name
fn partial_cmp(&self, other: &Name) -> Option<Ordering>
[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[src]
fn lt(&self, other: &Rhs) -> bool
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[src]
fn le(&self, other: &Rhs) -> bool
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[src]
fn gt(&self, other: &Rhs) -> bool
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[src]
fn ge(&self, other: &Rhs) -> bool
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]
impl Ord for Name
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
Case insensitive comparison, see [Name::cmp_case
] for case sensitive comparisons
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
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl FromStr for Name
[src]
impl FromStr for Name
type Err = ProtoError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
fn from_str(s: &str) -> Result<Self, Self::Err>
Uses the Name::from_utf8 conversion on this string, see [from_ascii
] for ascii only, or for preserving case
impl<'a> IntoName for &'a Name
[src]
impl<'a> IntoName for &'a Name
fn into_name(self) -> ProtoResult<Name>
[src]
fn into_name(self) -> ProtoResult<Name>
Clones this into a new Name
impl IntoName for Name
[src]
impl IntoName for Name
fn into_name(self) -> ProtoResult<Name>
[src]
fn into_name(self) -> ProtoResult<Name>
Convert this into Name
impl TryParseIp for Name
[src]
impl TryParseIp for Name
fn try_parse_ip(&self) -> Option<RData>
[src]
fn try_parse_ip(&self) -> Option<RData>
Always returns none for Name, it assumes something that is already a name, wants to be a name