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.
- checksums.yaml +4 -4
- data/Cargo.lock +111 -5
- data/Gemfile +1 -1
- data/README.md +39 -81
- data/Rakefile +6 -8
- data/ext/osv/Cargo.toml +7 -1
- data/ext/osv/src/allocator.rs +13 -0
- data/ext/osv/src/csv/builder.rs +65 -176
- data/ext/osv/src/csv/mod.rs +5 -3
- data/ext/osv/src/csv/parser.rs +90 -14
- data/ext/osv/src/csv/record.rs +19 -6
- data/ext/osv/src/csv/record_reader.rs +172 -0
- data/ext/osv/src/csv/ruby_integration.rs +30 -0
- data/ext/osv/src/csv/ruby_reader.rs +174 -0
- data/ext/osv/src/lib.rs +1 -0
- data/ext/osv/src/reader.rs +27 -22
- data/ext/osv/src/utils.rs +5 -5
- data/lib/osv/version.rb +1 -1
- metadata +13 -15
- data/ext/osv/src/csv/read_impl.rs +0 -75
- data/ext/osv/src/csv/reader.rs +0 -57
data/ext/osv/src/csv/reader.rs
DELETED
@@ -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
|
-
}
|