Skip to content

Commit

Permalink
docs: add example for a couple of from_slice functions
Browse files Browse the repository at this point in the history
Mostly to make it clear the examples like the following are not valid:

    RelativeDname::from_slice(b"_submissions._tcp");
  • Loading branch information
WhyNotHugo committed Aug 23, 2023
1 parent 642331f commit ac3c809
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/base/name/dname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ impl Dname<[u8]> {

/// Creates a domain name from an octets slice.
///
/// Note that the input must be in wire format, as shown below.
///
/// # Examples
///
/// ```
/// Dname::from_slice(b"\x07example\x03com");

Check failure on line 172 in src/base/name/dname.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

failed to resolve: use of undeclared type `Dname`

Check failure on line 172 in src/base/name/dname.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

failed to resolve: use of undeclared type `Dname`
/// ```
///
/// # Errors
///
/// This will only succeed if `slice` contains a properly encoded
/// absolute domain name.
pub fn from_slice(slice: &[u8]) -> Result<&Self, DnameError> {
Expand Down
8 changes: 8 additions & 0 deletions src/base/name/relative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ impl RelativeDname<[u8]> {
}

/// Creates a relative domain name from an octet slice.
///
/// Note that the input must be in wire format, as shown below.
///
/// # Example
///
/// ```
/// RelativeDname::from_slice(b"\x0c_submissions\x04_tcp");

Check failure on line 145 in src/base/name/relative.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

failed to resolve: use of undeclared type `RelativeDname`

Check failure on line 145 in src/base/name/relative.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

failed to resolve: use of undeclared type `RelativeDname`
/// ```
pub fn from_slice(slice: &[u8]) -> Result<&Self, RelativeDnameError> {
Self::check_slice(slice)?;
Ok(unsafe { Self::from_slice_unchecked(slice) })
Expand Down

0 comments on commit ac3c809

Please sign in to comment.