falco_plugin/plugin/exported_tables/field/
private.rs

1use crate::plugin::exported_tables::metadata::HasMetadata;
2use anyhow::Error;
3use std::ffi::CStr;
4use std::ops::{Deref, DerefMut};
5
6/// Do not export the field via Falco tables API
7///
8/// This is a wrapper that tells the Rust SDK not to export a field to other plugins.
9/// It can be used to hold private plugin data or hold types that aren't supported
10/// by the API (collections, enums etc.)
11///
12/// This type implements [`Deref`] and [`DerefMut`], so you do not need any extra
13/// code when accessing the actual data.
14///
15/// **Note**: the wrapped type must implement [`Default`] as entries may be created
16/// over the plugin API without any interaction with your plugin code.
17#[derive(Debug)]
18pub struct Private<T>(T);
19
20impl<T> Deref for Private<T> {
21    type Target = T;
22
23    fn deref(&self) -> &Self::Target {
24        &self.0
25    }
26}
27
28impl<T> DerefMut for Private<T> {
29    fn deref_mut(&mut self) -> &mut Self::Target {
30        &mut self.0
31    }
32}
33
34impl<T: Default> HasMetadata for Private<T> {
35    type Metadata = ();
36
37    fn new_with_metadata(_tag: &'static CStr, _meta: &Self::Metadata) -> Result<Self, Error> {
38        Ok(Self(T::default()))
39    }
40}