Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
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
You can’t perform that action at this time.