osv 0.3.13 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,57 +0,0 @@
1
- use super::{parser::RecordParser, read_impl::ReadImpl};
2
- use magnus::{Error, Ruby};
3
- use std::{borrow::Cow, io::Read};
4
-
5
- pub struct RecordReader<T: RecordParser> {
6
- pub(crate) reader: ReadImpl<T>,
7
- }
8
-
9
- impl<T: RecordParser> RecordReader<T> {
10
- #[inline]
11
- pub(crate) fn get_headers(
12
- ruby: &Ruby,
13
- reader: &mut csv::Reader<impl Read>,
14
- has_headers: bool,
15
- ) -> Result<Vec<String>, Error> {
16
- let first_row = reader.headers().map_err(|e| {
17
- Error::new(
18
- ruby.exception_runtime_error(),
19
- Cow::Owned(format!("Failed to read headers: {e}")),
20
- )
21
- })?;
22
-
23
- Ok(if has_headers {
24
- // Pre-allocate the vector with exact capacity
25
- let mut headers = Vec::with_capacity(first_row.len());
26
- headers.extend(first_row.iter().map(String::from));
27
- headers
28
- } else {
29
- // Pre-allocate the vector with exact capacity
30
- let mut headers = Vec::with_capacity(first_row.len());
31
- headers.extend((0..first_row.len()).map(|i| format!("c{i}")));
32
- headers
33
- })
34
- }
35
- }
36
-
37
- impl<T: RecordParser> Iterator for RecordReader<T> {
38
- type Item = T::Output;
39
-
40
- #[inline]
41
- fn next(&mut self) -> Option<Self::Item> {
42
- self.reader.next()
43
- }
44
-
45
- #[inline]
46
- fn size_hint(&self) -> (usize, Option<usize>) {
47
- // We can't know the exact size without reading the whole file
48
- (0, None)
49
- }
50
- }
51
-
52
- impl<T: RecordParser> Drop for RecordReader<T> {
53
- #[inline]
54
- fn drop(&mut self) {
55
- self.reader.cleanup();
56
- }
57
- }