Download codex-rs/core/src/utils/json.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 624 Bytes
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/core/src/utils/json.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/core/src/utils/json.rs
-
curl -L -o json.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/core/src/utils/json.rs
624 Bytes
| 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) | |
| } | |