Skip to main content

LineTag

Struct LineTag 

pub struct LineTag {
    pub timestamp: Duration,
    pub segments: Vec<SegmentTag>,
}
Expand description

A single line in the synced lyrics.

Fields§

§timestamp: Duration

The timestamp at which the line starts.

Can be the same as or earlier than the timestamp of first segment (if the A2 extension is used).

§segments: Vec<SegmentTag>

Timestamped segments of the line.

With regular LRC files, this will contain at most one element. If the enhanced LRC format is used, it may contain more elements.

Implementations§

§

impl LineTag

pub fn new(timestamp: Duration, content: String) -> LineTag

Create a new line tag with a single segment with the same timestamp.

§Examples
assert_eq!(
    LineTag::new(Duration::from_secs(1), "La la la".to_string()),
    // You can save a lot of boilerplate code
    LineTag {
        timestamp: Duration::from_secs(1),
        segments: vec![SegmentTag {
            timestamp: Duration::from_secs(1),
            content: "La la la".to_string()
        }]
    }
);

pub fn timestamp(&mut self, timestamp: Duration) -> Option<&mut LineTag>

Sets the timestamp of the line.

Returns None if the timestamp is later than the first segment of the line.

pub fn segment( &mut self, segment: SegmentTag, ) -> Result<&mut LineTag, TimestampError>

Adds a segment to the line.

Prefer using this method over manually adding segments to lines as it ensures that the timestamp order stays correct. If you need to add segments manually, use the check_timestamp_order method to verify the timestamp order.

pub fn segments( &mut self, segments: &[SegmentTag], ) -> Result<&mut LineTag, TimestampError>

Adds multiple segments to the line.

Prefer using this method over manually adding segments to lines as it ensures that the timestamp order stays correct. If you need to add segments manually, use the check_timestamp_order method to verify the timestamp order.

Trait Implementations§

§

impl Clone for LineTag

§

fn clone(&self) -> LineTag

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
§

impl Debug for LineTag

§

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

Formats the value using the given formatter. Read more
§

impl Default for LineTag

§

fn default() -> LineTag

Returns the “default value” for a type. Read more
§

impl Eq for LineTag

§

impl<'a> From<TimestampedTag<'a>> for LineTag

Available on crate feature parser only.
§

fn from(value: TimestampedTag<'_>) -> LineTag

Converts to this type from the input type.
§

impl Hash for LineTag

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl LyricsAccess<LineTag> for SyncedLyrics

§

fn is_active(&self, timestamp: Duration) -> bool

Returns whether the lyrics are active for the given timestamp.

Lyrics are considered active if timestamp is greater than or equal to the timestamp of the first line of the lyrics. The first line is assumed to have the earliest timestamp, so if the line order is not correct this method may return wrong results.

§Examples
let lyrics = SyncedLyrics::try_new(vec![
    LineTag {
        // Checking whether lyrics are active is delegated to the first line
        timestamp: Duration::from_secs(11),
        segments: vec![
            SegmentTag::new(Duration::from_secs(12), String::new()),
            SegmentTag::new(Duration::from_secs(15), String::new())
        ]
    },
    // All other stuff doesn't matter
    LineTag {
        timestamp: Duration::from_secs(17),
        segments: vec![SegmentTag::new(Duration::from_secs(17), String::new())]
    }
])
.unwrap();

assert!(!lyrics.is_active(Duration::default()));
assert!(!lyrics.is_active(Duration::from_secs(3)));
assert!(lyrics.is_active(Duration::from_secs(11)));
assert!(lyrics.is_active(Duration::from_secs(67)));
assert!(lyrics.is_active(Duration::from_secs(u64::MAX)));
§

fn to_unsynced(self) -> String

Returns unsynced lyrics without timestamps or additional metadata. Read more
§

fn active_tag_index(&self, timestamp: Duration) -> Option<usize>

Returns the index of the active tag or None if no tag is active for the given timestamp. Read more
§

fn active_tag(&self, timestamp: Duration) -> Option<&LineTag>

Returns the active tag or None if no tag is active for the given timestamp. Read more
§

fn check_timestamp_order(&self) -> Result<(), TimestampError>

Checks if timed tag timestamps are ordered correctly. Read more
§

fn is_enhanced_lrc(&self) -> bool

Returns whether the element contains tags indicating that it uses the enhanced LRC format. Read more
§

impl LyricsAccess<SegmentTag> for LineTag

§

fn is_active(&self, timestamp: Duration) -> bool

Returns whether the line is active for the given timestamp.

A line is considered active if timestamp is greater than or equal to the line timestamp. The line timestamp is considered to be the earliest, so if any of the segments have a timestamp that is earlier than the line timestamp, this method will return wrong results.

§Examples
let line = LineTag {
    // Only this timestamp is considered when evaluating whether the line is active or not
    timestamp: Duration::from_secs(5),
    // Those segments don't actually matter here
    segments: vec![
        SegmentTag::new(Duration::from_secs(5), String::new()),
        SegmentTag::new(Duration::from_secs(7), String::new()),
    ],
};

assert!(!line.is_active(Duration::default()));
assert!(!line.is_active(Duration::from_secs(3)));
assert!(line.is_active(Duration::from_secs(5)));
assert!(line.is_active(Duration::from_secs(23)));
assert!(line.is_active(Duration::from_secs(u64::MAX)));
§

fn to_unsynced(self) -> String

Returns unsynced lyrics without timestamps or additional metadata. Read more
§

fn active_tag_index(&self, timestamp: Duration) -> Option<usize>

Returns the index of the active tag or None if no tag is active for the given timestamp. Read more
§

fn active_tag(&self, timestamp: Duration) -> Option<&SegmentTag>

Returns the active tag or None if no tag is active for the given timestamp. Read more
§

fn check_timestamp_order(&self) -> Result<(), TimestampError>

Checks if timed tag timestamps are ordered correctly. Read more
§

fn is_enhanced_lrc(&self) -> bool

Returns whether the element contains tags indicating that it uses the enhanced LRC format. Read more
§

impl Ord for LineTag

§

fn cmp(&self, other: &LineTag) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
§

impl PartialEq for LineTag

§

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

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

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

Inequality operator !=. Read more
§

impl PartialOrd for LineTag

§

fn partial_cmp(&self, other: &LineTag) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl StructuralPartialEq for LineTag

Auto Trait Implementations§

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
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more