Methods
new
pub fn new(reader: Read, delimiter: char = ',', comment: char? = nil, has_headers: bool = true): Reader
[src]
pub fn new(
reader: Read, delimiter: char = ',', comment: char? = nil, has_headers: bool = true
): Reader {
return _csv.Reader.new(_create_native_read(reader), delimiter, comment, has_headers) as Reader;
}
Creates a new CSV reader from a std.io.Read
.
new
pub fn new(reader: Read, delimiter: char = ',', comment: char? = nil, has_headers: bool = true): Reader
[src]
pub fn new(
reader: Read, delimiter: char = ',', comment: char? = nil, has_headers: bool = true
): Reader {
return _csv.Reader.new(_create_native_read(reader), delimiter, comment, has_headers) as Reader;
}
Creates a new CSV reader from a std.io.Read
.
Creates a new CSV reader from a std.io.Read
.
Options
delimiter
- A char that separates fields in a record, default:,
.comment
- A char that starts a comment, default:nil
.has_headers
- Whether to treat the first row as a special header row, default:true
.
The reader is a streaming CSV parser.
[src]
pub fn headers(self): Record throws CsvError, IoError, Utf8Error {
let record = try (self as _csv.Reader).headers();
return record as Record;
}
Returns the first record as headers.
[src]
pub fn headers(self): Record throws CsvError, IoError, Utf8Error {
let record = try (self as _csv.Reader).headers();
return record as Record;
}
Returns the first record as headers.
Returns the first record as headers.
- If no record has been read yet, then this will force parsing of the first record.
- If there was a problem parsing the record or if it wasn't valid UTF-8, then this returns an error.
- If the underlying reader emits EOF before any data, then this returns an empty record.
Example
nv
use csv.Reader;
use std.io.{Read, Cursor};
let cursor = Cursor.new("hello,100".bytes());
let reader = Reader.new(cursor);
let record = try! reader.headers();
[src]
pub fn next(self): Record? throws CsvError, IoError, Utf8Error {
if (let record = try (self as _csv.Reader).next()) {
return record as Record;
} else {
return nil;
}
}
Returns the next record.
[src]
pub fn next(self): Record? throws CsvError, IoError, Utf8Error {
if (let record = try (self as _csv.Reader).next()) {
return record as Record;
} else {
return nil;
}
}
Returns the next record.
Returns the next record.
- If the record is invalid UTF-8, then this returns an error.
- If the underlying reader emits EOF, then this returns
nil
.
Example
nv
use csv.Reader;
use std.io.{Read, Cursor};
let cursor = Cursor.new("hello,100".bytes());
let record = try! Reader.new(cursor).next();
[src]
pub fn scan<T>(self): T? throws CsvError, IoError, Utf8Error {
return try (self as _csv.Reader).scan::<T>();
}
Get the next record and deserialize it.
[src]
pub fn scan<T>(self): T? throws CsvError, IoError, Utf8Error {
return try (self as _csv.Reader).scan::<T>();
}
Get the next record and deserialize it.
Get the next record and deserialize it.
Example
nv
use std.io.Cursor;
use csv.Reader;
struct Record {
name: string,
value: int,
}
let csv = `
name,value
a,10
b,20
c,30
`;
fn main() throws {
let reader = Reader.new(Cursor.new(csv));
assert_eq try reader.scan::<Record>(), Record { name: "a", value: 10 };
assert_eq try reader.scan::<Record>(), Record { name: "b", value: 20 };
assert_eq try reader.scan::<Record>(), Record { name: "c", value: 30 };
}
[src]
pub fn position(self): Position {
return (self as _csv.Reader).position;
}
Returns the current position in the CSV.
[src]
pub fn position(self): Position {
return (self as _csv.Reader).position;
}
Returns the current position in the CSV.
Returns the current position in the CSV.
Example
nv
use std.io.{Cursor, Read};
use csv.Reader;
let csv = `name,value
a,10
b,20
c,30`;
fn main() throws {
let cursor = Cursor.new(csv);
let reader = Reader.new(cursor, has_headers: false);
assert_eq reader.position().line, 1;
assert_eq reader.position().byte, 0;
let record = try reader.next();
assert_eq reader.position().line, 2;
assert_eq reader.position().byte, 11;
let record = try reader.next();
assert_eq reader.position().line, 3;
assert_eq reader.position().byte, 16;
let record = try reader.next();
assert_eq reader.position().line, 4;
assert_eq reader.position().byte, 21;
}