#[non_exhaustive]pub enum Edit {
SetTime {
line: usize,
seconds: f64,
},
Shift {
seconds: f64,
lines: Option<Vec<usize>>,
from: Option<usize>,
},
SortByTime,
SetRest {
line: usize,
rest: String,
},
Insert {
after: usize,
text: String,
},
Delete {
line: usize,
},
}Expand description
One edit of a tracklist text (R13.9). Line numbers are 1-based and refer to the text as the previous edit left it.
The JSON form is the spec’s ({"op":"set-time","line":3,"seconds":90}).
use trackparse::tracklist::{apply_edits, Edit};
let text = "00:00 A - B\n01:00 C - D\n";
let edits = [Edit::set_time(2, 90.0), Edit::insert(2, "02:00 E - F"), Edit::delete(1)];
assert_eq!(apply_edits(text, &edits).text, "01:30 C - D\n02:00 E - F\n");
assert_eq!(edits[0].to_json(), r#"{"op":"set-time","line":2,"seconds":90}"#);
assert_eq!(edits[0], Edit::SetTime { line: 2, seconds: 90.0 });Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
SetTime
Rewrite the time of line, keeping its written style (R13.9.2).
Shift
Add seconds to every timed line of lines, else from line from on, else of the
whole text.
Fields
SortByTime
Stable sort of the timed lines, each with the untimed lines after it (R13.9.4).
SetRest
Replace everything after the time and gap of line.
Insert
Insert text as a new line after line after (0: at the start).
Delete
Remove line.
Implementations§
Source§impl Edit
impl Edit
Sourcepub fn shift(seconds: f64) -> Edit
pub fn shift(seconds: f64) -> Edit
Edit::Shift over every timed line of the text.
use trackparse::tracklist::{apply_edits, Edit};
let result = apply_edits("00:10 A - B\n01:00 C - D", &[Edit::shift(-10.0)]);
assert_eq!(result.text, "00:00 A - B\n00:50 C - D");Sourcepub fn shift_from(seconds: f64, from: usize) -> Edit
pub fn shift_from(seconds: f64, from: usize) -> Edit
Edit::Shift over line from and the lines after it.
Sourcepub fn shift_lines(seconds: f64, lines: impl IntoIterator<Item = usize>) -> Edit
pub fn shift_lines(seconds: f64, lines: impl IntoIterator<Item = usize>) -> Edit
Edit::Shift over the given lines only.
Sourcepub fn sort_by_time() -> Edit
pub fn sort_by_time() -> Edit
Sourcepub fn set_rest(line: usize, rest: impl Into<String>) -> Edit
pub fn set_rest(line: usize, rest: impl Into<String>) -> Edit
Edit::SetRest: replace what follows the time of line.
Sourcepub fn insert(after: usize, text: impl Into<String>) -> Edit
pub fn insert(after: usize, text: impl Into<String>) -> Edit
Edit::Insert: a new line after line after (0: at the start).
Sourcepub fn delete(line: usize) -> Edit
pub fn delete(line: usize) -> Edit
Edit::Delete: remove line.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Edit
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Edit
serde only.