#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![allow(unexpected_cfgs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, allow(unused_attributes))]
#![allow(clippy::needless_return)]
#![allow(unreachable_code)]
#[cfg(feature = "slab")]
pub use slab;
pub use srv::*;
pub use txt::*;
pub mod error;
pub mod server;
pub mod client;
pub mod proto {
pub use super::srv::Srv;
pub use super::txt::{Str, Strings, Txt};
pub use dns_protocol::{
Cursor, Deserialize, Flags, Header, Label, LabelSegment, Message, MessageType, Opcode,
Question, ResourceRecord, ResourceType, ResponseCode, Serialize,
};
}
mod srv;
mod txt;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct ConnectionHandle(pub usize);
impl From<ConnectionHandle> for usize {
fn from(x: ConnectionHandle) -> Self {
x.0
}
}
impl core::fmt::Display for ConnectionHandle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.0)
}
}
pub trait Pool<V> {
type Error: core::error::Error;
type Iter<'a>: Iterator<Item = (usize, &'a V)>
where
Self: 'a,
V: 'a;
fn new() -> Self;
fn with_capacity(capacity: usize) -> Result<Self, Self::Error>
where
Self: Sized;
fn vacant_key(&self) -> Result<usize, Self::Error>;
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn get(&self, key: usize) -> Option<&V>;
fn get_mut(&mut self, key: usize) -> Option<&mut V>;
fn insert(&mut self, value: V) -> Result<usize, Self::Error>;
fn try_remove(&mut self, key: usize) -> Option<V>;
fn iter(&self) -> Self::Iter<'_>;
}
#[cfg(feature = "slab")]
impl<T> Pool<T> for slab::Slab<T> {
type Error = core::convert::Infallible;
type Iter<'a>
= slab::Iter<'a, T>
where
Self: 'a;
fn new() -> Self {
slab::Slab::new()
}
fn with_capacity(capacity: usize) -> Result<Self, Self::Error>
where
Self: Sized,
{
Ok(slab::Slab::with_capacity(capacity))
}
fn vacant_key(&self) -> Result<usize, Self::Error> {
Ok(slab::Slab::vacant_key(self))
}
fn is_empty(&self) -> bool {
slab::Slab::is_empty(self)
}
fn len(&self) -> usize {
slab::Slab::len(self)
}
fn get(&self, key: usize) -> Option<&T> {
slab::Slab::get(self, key)
}
fn get_mut(&mut self, key: usize) -> Option<&mut T> {
slab::Slab::get_mut(self, key)
}
fn insert(&mut self, value: T) -> Result<usize, Self::Error> {
Ok(slab::Slab::insert(self, value))
}
fn try_remove(&mut self, key: usize) -> Option<T> {
slab::Slab::try_remove(self, key)
}
fn iter(&self) -> Self::Iter<'_> {
slab::Slab::iter(self)
}
}