Skip to main content

Module csv

Module csv 

Source
Available on crate feature csv only.
Expand description

Named peers from CSV text. Needs the csv feature.

Local trust has one from,to[,weight] record per line, pre-trust one peer[,weight] record. Peer names are arbitrary strings and weights default to 1.

use eigentrust::csv::Network;
use eigentrust::EigenTrustOptions;

let network = Network::from_csv(
    "from,to,weight\nalice,bob,2\nbob,carol,1\ncarol,alice,1\n",
    "alice\n",
)?;
let result = network.eigentrust(&EigenTrustOptions::default())?;
let ranking = network.ranking(&result);
assert_eq!(ranking[0].0, "alice");

The reader accepts standard CSV: quoted fields ("Smith, J"), escaped quotes, an optional header row, spaces around fields, CRLF line endings and a UTF-8 BOM. Blank lines are skipped and columns after the weight are ignored.

The first record is a header when its weight column is not a number, or, for records without a weight column, when every field is a common header name such as from, to, peer or weight. A weight that fails to parse on any later line is an error.

Structs§

Error
A CSV record that could not be read.
Network
A network with named peers, read from CSV.

Enums§

ErrorKind
What is wrong with a CSV record.