Base: codex-main originale (prima del fork aKode)
This commit is contained in:
22
codex-rs/core/src/utils/json.rs
Normal file
22
codex-rs/core/src/utils/json.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
#[derive(Default)]
|
||||
struct JsonByteCounter(usize);
|
||||
|
||||
impl std::io::Write for JsonByteCounter {
|
||||
fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {
|
||||
self.0 = self.0.saturating_add(bytes.len());
|
||||
Ok(bytes.len())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Counts serialized JSON bytes without retaining the serialized output.
|
||||
pub(crate) fn serialized_json_bytes<T: serde::Serialize + ?Sized>(
|
||||
value: &T,
|
||||
) -> serde_json::Result<usize> {
|
||||
let mut counter = JsonByteCounter::default();
|
||||
serde_json::to_writer(&mut counter, value)?;
|
||||
Ok(counter.0)
|
||||
}
|
||||
2
codex-rs/core/src/utils/mod.rs
Normal file
2
codex-rs/core/src/utils/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub(crate) mod json;
|
||||
pub mod path_utils;
|
||||
1
codex-rs/core/src/utils/path_utils.rs
Normal file
1
codex-rs/core/src/utils/path_utils.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub use codex_utils_path::*;
|
||||
Reference in New Issue
Block a user