Skip to main content

apply_edits

Function apply_edits 

Source
pub fn apply_edits(text: &str, edits: &[Edit]) -> EditResult
Expand description

Apply edits to a tracklist text (R13.9), in order, each to the result of the previous one.

Lines no edit wrote stay byte-identical. Never panics: an edit that cannot be applied changes nothing and is reported as EditWarningCode::EditInvalid.

use trackparse::tracklist::{apply_edits, Edit};

let text = "00:00 Noisia - Stigma\n03:45 Phace - Cold Champagne\n";
let edits = [
    Edit::shift_from(30.0, 2),
    Edit::set_rest(1, "Noisia - Stigma (Neosignal Remix)"),
];
let result = apply_edits(text, &edits);
assert_eq!(result.text, "00:00 Noisia - Stigma (Neosignal Remix)\n04:15 Phace - Cold Champagne\n");
assert_eq!(result.changed, [1, 2]);
assert!(result.warnings.is_empty());