pub trait CapInspect {
fn cap_inspect_at(&self, name: &'static str, file: &'static str, line: u32, column: u32);
}
#[cfg(feature = "telemetry")]
mod with_telemetry {
use super::CapInspect;
use crate::registry;
impl<T> CapInspect for Vec<T> {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<T> CapInspect for std::collections::VecDeque<T> {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K, V, S> CapInspect for std::collections::HashMap<K, V, S>
where
K: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<T, S> CapInspect for std::collections::HashSet<T, S>
where
T: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K: Ord, V> CapInspect for std::collections::BTreeMap<K, V> {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.len());
}
}
impl<T: Ord> CapInspect for std::collections::BTreeSet<T> {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.len());
}
}
impl CapInspect for ::bytes::BytesMut {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K, V, S> CapInspect for ::indexmap::IndexMap<K, V, S>
where
K: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<T, S> CapInspect for ::indexmap::IndexSet<T, S>
where
T: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K, V, S> CapInspect for ::dashmap::DashMap<K, V, S>
where
K: Eq + std::hash::Hash,
S: std::hash::BuildHasher + Clone,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K, V, S> CapInspect for ::scc::HashMap<K, V, S>
where
K: Eq + std::hash::Hash + 'static,
V: 'static,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<T, S> CapInspect for ::scc::HashSet<T, S>
where
T: Eq + std::hash::Hash + 'static,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K, V> CapInspect for ::scc::TreeIndex<K, V>
where
K: Clone + Ord + 'static,
V: Clone + 'static,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
#[allow(clippy::disallowed_methods)] registry::record_sample(file, line, column, self.len());
}
}
impl<A: ::smallvec::Array> CapInspect for ::smallvec::SmallVec<A> {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl CapInspect for String {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<T: Ord> CapInspect for std::collections::BinaryHeap<T> {
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
impl<K, V, S> CapInspect for ::hashbrown::HashMap<K, V, S>
where
K: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline]
fn cap_inspect_at(&self, _name: &'static str, file: &'static str, line: u32, column: u32) {
registry::record_sample(file, line, column, self.capacity());
}
}
}
#[cfg(not(feature = "telemetry"))]
mod without_telemetry {
use super::CapInspect;
impl<T> CapInspect for Vec<T> {
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl<T> CapInspect for std::collections::VecDeque<T> {
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl<K, V, S> CapInspect for std::collections::HashMap<K, V, S>
where
K: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl<T, S> CapInspect for std::collections::HashSet<T, S>
where
T: Eq + std::hash::Hash,
S: std::hash::BuildHasher,
{
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl<K: Ord, V> CapInspect for std::collections::BTreeMap<K, V> {
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl<T: Ord> CapInspect for std::collections::BTreeSet<T> {
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl CapInspect for String {
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
impl<T: Ord> CapInspect for std::collections::BinaryHeap<T> {
#[inline(always)]
fn cap_inspect_at(
&self,
_name: &'static str,
_file: &'static str,
_line: u32,
_column: u32,
) {
}
}
}