pub fn extract_assignment_ben<R: Read>(
    reader: R,
    sample_number: usize
) -> Result<Vec<u16>, SampleError>
Expand description

Extracts a single assignment from a binary-encoded data stream.

§Arguments

  • reader - The reader to extract the assignment from.
  • sample_number - The sample number to extract.

§Returns

This function returns a Result containing a Vec<u16> of the assignment if successful, or a SampleError if an error occurred.

§Example

use ben::decode::read::extract_assignment_ben;
use std::{fs::File, io::BufReader};

let file = File::open("data.jsonl.ben").unwrap();
let reader = BufReader::new(file);
let sample_number = 2;

let result = extract_assignment_ben(reader, sample_number);
match result {
    Ok(assignment) => {
        eprintln!("Extracted assignment: {:?}", assignment);
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}

§Errors

This function can return a SampleError if an error occurs during the extraction process. The error can be one of the following:

  • InvalidSampleNumber - The sample number is invalid. All sample numbers must be greater than 0.
  • SampleNotFound - The sample number was not found in the file. The last sample number is provided.
  • IoError - An IO error occurred during the extraction process.
  • JsonError - A JSON error occurred during the extraction process.