Skip to main content

Edit

Enum Edit 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

SetTime

Rewrite the time of line, keeping its written style (R13.9.2).

Fields

§line: usize

The line to change.

§seconds: f64

The new time in seconds.

§

Shift

Add seconds to every timed line of lines, else from line from on, else of the whole text.

Fields

§seconds: f64

Seconds to add; negative moves the times back.

§lines: Option<Vec<usize>>

Only these lines.

§from: Option<usize>

Only this line and the ones after it.

§

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.

Fields

§line: usize

The line to change.

§rest: String

The new text after the time.

§

Insert

Insert text as a new line after line after (0: at the start).

Fields

§after: usize

The line to insert after.

§text: String

The new line, without a terminator.

§

Delete

Remove line.

Fields

§line: usize

The line to remove.

Implementations§

Source§

impl Edit

Source

pub fn set_time(line: usize, seconds: f64) -> Edit

Edit::SetTime: rewrite the time of line.

Source

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");
Source

pub fn shift_from(seconds: f64, from: usize) -> Edit

Edit::Shift over line from and the lines after it.

Source

pub fn shift_lines(seconds: f64, lines: impl IntoIterator<Item = usize>) -> Edit

Edit::Shift over the given lines only.

Source

pub fn sort_by_time() -> Edit

Source

pub fn set_rest(line: usize, rest: impl Into<String>) -> Edit

Edit::SetRest: replace what follows the time of line.

Source

pub fn insert(after: usize, text: impl Into<String>) -> Edit

Edit::Insert: a new line after line after (0: at the start).

Source

pub fn delete(line: usize) -> Edit

Edit::Delete: remove line.

Source§

impl Edit

Source

pub fn to_json(&self) -> String

The spec’s JSON form as compact text: camelCase keys, every key present, in the schema’s order. The same text the JavaScript and Python packages give.

Trait Implementations§

Source§

impl Clone for Edit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Edit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Edit

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Edit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Edit

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Edit

Source§

impl ToJson for Edit

Source§

fn to_json_value(&self) -> Json

The edit as the spec writes it ({"op":"set-time","line":3,"seconds":90}).

Source§

fn to_json(&self) -> String

Compact JSON text.

Auto Trait Implementations§

§

impl Forget for Edit

§

impl Freeze for Edit

§

impl Move for Edit

§

impl RefUnwindSafe for Edit

§

impl Send for Edit

§

impl Sync for Edit

§

impl Unpin for Edit

§

impl UnsafeUnpin for Edit

§

impl UnwindSafe for Edit

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.