Created
March 20, 2019 03:40
-
-
Save rust-play/d435512e6c222127c40bbbe48c9d6cf2 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bytes::Bytes; | |
use futures::Stream; | |
use std::net::SocketAddr; | |
pub struct ServFail; | |
/// `Handler` is cloned and then `.handle()` is called for each incoming message. | |
pub trait Handler: Clone { | |
/// Returning `Err(ServFail)` generates a SERVFAIL response. | |
fn handle(&self, query: Query) -> Result<(), ServFail>; | |
} | |
pub struct Query {/* */} | |
impl Query { | |
/// Message as a byte slice. | |
pub fn as_slice(&self) -> &[u8] { | |
unimplemented!(); | |
} | |
/// Message as `Bytes`. | |
pub fn as_bytes(&self) -> Bytes { | |
unimplemented!(); | |
} | |
/// Source of the message. | |
pub fn from(&self) -> SocketAddr { | |
unimplemented!(); | |
} | |
/// Address where the message was recieved. | |
pub fn to(&self) -> SocketAddr { | |
unimplemented!(); | |
} | |
/// True if recieved over a secure transport (TLS, etc). | |
pub fn secure(&self) -> bool { | |
unimplemented!(); | |
} | |
/// True if recieved over a connected transport (TCP, TLS, etc). | |
pub fn connected(&self) -> bool { | |
unimplemented!(); | |
} | |
/// Respond to a query by providing something that implements a `Stream` of `Bytes`. | |
/// Each `Bytes` represents one message. Length prefix will be added if appropriate. | |
/// A multiple message response over a non-connected transport is allowed. | |
pub fn respond<S>(self, _stream: S) | |
where | |
S: Stream<Item = Bytes, Error = ()>, | |
{ | |
unimplemented!(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment