pub struct Codec { /* private fields */ }Expand description
JSONL conversation codec.
Use Codec::new() for plain JSONL. Pass a redact callback via
Codec::with_redact to transform each message before encoding.
Implementations§
Source§impl Codec
impl Codec
Sourcepub fn with_redact(
redact: impl Fn(Value) -> Value + Send + Sync + 'static,
) -> Self
pub fn with_redact( redact: impl Fn(Value) -> Value + Send + Sync + 'static, ) -> Self
Codec that applies redact to each message before encoding.
Sourcepub fn save(
&self,
messages: &[Value],
path: impl AsRef<Path>,
) -> Result<(), CodecError>
pub fn save( &self, messages: &[Value], path: impl AsRef<Path>, ) -> Result<(), CodecError>
Write messages to a JSONL file. Creates parent dirs; overwrites.
Sourcepub fn append(
&self,
messages: &[Value],
path: impl AsRef<Path>,
) -> Result<(), CodecError>
pub fn append( &self, messages: &[Value], path: impl AsRef<Path>, ) -> Result<(), CodecError>
Append messages to an existing JSONL file (creates if absent).
Sourcepub fn load(&self, path: impl AsRef<Path>) -> Result<Vec<Value>, CodecError>
pub fn load(&self, path: impl AsRef<Path>) -> Result<Vec<Value>, CodecError>
Load all messages from a JSONL file. Skips blank lines.
Sourcepub fn decode_line(line: &str) -> Result<Value, CodecError>
pub fn decode_line(line: &str) -> Result<Value, CodecError>
Decode a single JSONL line.
Sourcepub fn encode_line(&self, msg: Value) -> String
pub fn encode_line(&self, msg: Value) -> String
Encode a single message to a JSONL line (applies redact if set).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Codec
impl !RefUnwindSafe for Codec
impl Send for Codec
impl Sync for Codec
impl Unpin for Codec
impl UnsafeUnpin for Codec
impl !UnwindSafe for Codec
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