apple-quant-core 0.2.0

Apple Quant's core library.
Documentation
use std::ops::Deref;

use smallvec::SmallVec;

use tracing::field::{Field, Visit};

#[derive(Default, Debug, Clone)]
pub(crate) struct Fields(SmallVec<[(&'static str, String); 8]>);

impl Fields {
	pub(crate) fn push(
		&mut self,
		name: &'static str,
		value: impl Into<String>,
	) {
		self.0.push((name, value.into()));
	}
}

impl Visit for Fields {
	fn record_str(
		&mut self,
		field: &Field,
		value: &str,
	) {
		self.0.push((field.name(), value.to_owned()));
	}

	fn record_debug(
		&mut self,
		field: &Field,
		value: &dyn std::fmt::Debug,
	) {
		self.0.push((field.name(), format!("{:#?}", value)));
	}
}

impl Deref for Fields {
	type Target = SmallVec<[(&'static str, String); 8]>;

	fn deref(
		&self,
	) -> &Self::Target {
		&self.0
	}
}