pub struct JsonSlicer { /* private fields */ }Expand description
Condenses JSON responses.
§Example
use boundgraph_slice::{JsonSlicer, MemoryStore, Raw, Slicer};
let body = serde_json::json!({
"users": (0..5_000).map(|i| serde_json::json!({ "id": i })).collect::<Vec<_>>(),
"api_key": "sk-live-do-not-leak-this",
});
let condensate = tokio::runtime::Builder::new_current_thread()
.build()?
.block_on(JsonSlicer::new().condense(
&Raw::new(body.to_string()),
300,
&MemoryStore::new(),
))?;
let payload = format!("{:?}", condensate.payload);
assert!(!payload.contains("do-not-leak-this"), "the key never reaches the model");Implementations§
Source§impl JsonSlicer
impl JsonSlicer
Sourcepub fn sampling(self, elements: usize, max_depth: usize) -> Self
pub fn sampling(self, elements: usize, max_depth: usize) -> Self
Sample this many array elements, and elide below this depth.
Sourcepub fn redacting<S: Into<String>>(
self,
keys: impl IntoIterator<Item = S>,
) -> Self
pub fn redacting<S: Into<String>>( self, keys: impl IntoIterator<Item = S>, ) -> Self
Treat these field names as secret too, on top of the built-in list.
For a response whose credential field is called something nobody would guess. The built-in list is not replaced — narrowing it is not offered, because the cost of the two mistakes is not symmetric.
Trait Implementations§
Source§impl Clone for JsonSlicer
impl Clone for JsonSlicer
Source§impl Debug for JsonSlicer
impl Debug for JsonSlicer
Source§impl Default for JsonSlicer
impl Default for JsonSlicer
Source§impl Slicer for JsonSlicer
impl Slicer for JsonSlicer
Source§fn slice<'life0, 'life1, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
) -> Pin<Box<dyn Future<Output = Result<Slice, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn slice<'life0, 'life1, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
) -> Pin<Box<dyn Future<Output = Result<Slice, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Produce the summary. The part an implementation writes. Read more
Source§fn counter(&self) -> &dyn TokenCount
fn counter(&self) -> &dyn TokenCount
How this slicer counts tokens. Read more
Source§fn minimum_cap(&self) -> usize
fn minimum_cap(&self) -> usize
The least a summary from this slicer can cost. Read more
Source§fn condense<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
store: &'life2 dyn Store,
) -> Pin<Box<dyn Future<Output = Result<Condensate, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn condense<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
store: &'life2 dyn Store,
) -> Pin<Box<dyn Future<Output = Result<Condensate, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Preserve the original, slice it, and check the result fits. Read more
Auto Trait Implementations§
impl Freeze for JsonSlicer
impl RefUnwindSafe for JsonSlicer
impl Send for JsonSlicer
impl Sync for JsonSlicer
impl Unpin for JsonSlicer
impl UnsafeUnpin for JsonSlicer
impl UnwindSafe for JsonSlicer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more