Struct simple_dns::PacketBuf[][src]

pub struct PacketBuf { /* fields omitted */ }
Expand description

Owned version of Packet that contains a internal buffer.
This struct fills the internal buffer on the fly, because of this, it imposes some constraints.
You have to build the packet in order.
ex: It is not possible to add a question after an answer

Implementations

Creates a new empty PacketBuf

Creates a new empty PacketBuf with a query header

Add a Question to this packet.
This function will fail if the packet already has any answer, name server or additional records

Add a Answer to this packet.
This function will fail if the packet already has any name server or additional records

Add a Name Server to this packet.
This function will fail if the packet already has any additional records

Add an Additional Record to this packet

Return the packet id from this packet header

Creates a Packet by calling the Packet::parse function

Return true if this packet has any answers

Return true if this packet has questions

Return true if this packet has any name servers

Return true if this packet has any additional records

Returns an Iterator over questions of this packet

Methods from Deref<Target = Vec<u8>>

Returns the number of elements the vector can hold without reallocating.

Examples

let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);

Extracts a slice containing the entire vector.

Equivalent to &s[..].

Examples

use std::io::{self, Write};
let buffer = vec![1, 2, 3, 5, 8];
io::sink().write(buffer.as_slice()).unwrap();

Returns a raw pointer to the vector’s buffer.

The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.

The caller must also ensure that the memory the pointer (non-transitively) points to is never written to (except inside an UnsafeCell) using this pointer or any pointer derived from it. If you need to mutate the contents of the slice, use as_mut_ptr.

Examples

let x = vec![1, 2, 4];
let x_ptr = x.as_ptr();

unsafe {
    for i in 0..x.len() {
        assert_eq!(*x_ptr.add(i), 1 << i);
    }
}
🔬 This is a nightly-only experimental API. (allocator_api)

Returns a reference to the underlying allocator.

Returns the number of elements in the vector, also referred to as its ‘length’.

Examples

let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

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