Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 20, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/d5f2f09092039774b1f786d87cf143a0 to your computer and use it in GitHub Desktop.
Save rust-play/d5f2f09092039774b1f786d87cf143a0 to your computer and use it in GitHub Desktop.
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 received.
pub fn to(&self) -> SocketAddr {
unimplemented!();
}
/// True if received over a secure transport (TLS, etc).
pub fn secure(&self) -> bool {
unimplemented!();
}
/// True if received 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