pub struct Server { /* private fields */ }Expand description
A simple mock server for DNS requests.
The intended usage is to create a new instance using Server::default() and add some record
mappings to it. You can then bind a UdpSocket and start the server with Server::start()
in a background task before making requests on the main thread.
Implementations§
Source§impl Server
impl Server
Sourcepub fn add_records(
&mut self,
name: &str,
records: Vec<IpAddr>,
) -> Result<(), ProtoError>
pub fn add_records( &mut self, name: &str, records: Vec<IpAddr>, ) -> Result<(), ProtoError>
Adds a mapping from a DNS record to some IP addresses.
§Example
let mut server = Server::default();
let records = vec![IpAddr::V4(Ipv4Addr::LOCALHOST)];
server.add_records("example.com", records).expect("Invalid hostname");Sourcepub async fn start(self, socket: UdpSocket) -> Result<(), ProtoError>
pub async fn start(self, socket: UdpSocket) -> Result<(), ProtoError>
Starts the mock server on the given UdpSocket.
This should be run in a background task using a method such as tokio::spawn.
Trait Implementations§
Source§impl RequestHandler for Server
impl RequestHandler for Server
Source§fn handle_request<'life0, 'life1, 'async_trait, R>(
&'life0 self,
request: &'life1 Request,
response_handler: R,
) -> Pin<Box<dyn Future<Output = ResponseInfo> + Send + 'async_trait>>where
R: 'async_trait + ResponseHandler,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle_request<'life0, 'life1, 'async_trait, R>(
&'life0 self,
request: &'life1 Request,
response_handler: R,
) -> Pin<Box<dyn Future<Output = ResponseInfo> + Send + 'async_trait>>where
R: 'async_trait + ResponseHandler,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Determines what needs to happen given the type of request, i.e. Query or Update. Read more
Auto Trait Implementations§
impl Freeze for Server
impl RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl UnwindSafe for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more