Skip to main content

SyncedLyrics

Struct SyncedLyrics 

pub struct SyncedLyrics {
    pub title: Option<String>,
    pub artist: Option<String>,
    pub album: Option<String>,
    pub author: Option<String>,
    pub lyricist: Option<String>,
    pub length: Option<Duration>,
    pub file_author: Option<String>,
    pub tool: Option<LRCTool>,
    pub comments: Vec<String>,
    pub lines: Vec<LineTag>,
}
Expand description

Lyrics grouped into timestamped segments with additional metadata.

Fields§

§title: Option<String>

Title of the song.

§artist: Option<String>

Artist performing the song.

§album: Option<String>

Album the song is from.

§author: Option<String>

Author of the song.

§lyricist: Option<String>

Lyricist of the song.

§length: Option<Duration>

Length of the song.

§file_author: Option<String>

Author of the LRC file (not the song).

§tool: Option<LRCTool>

Info on the player or editor that created the LRC file.

§comments: Vec<String>

Comments found in the lyrics.

§lines: Vec<LineTag>

LRC segments grouped by lines.

Implementations§

§

impl SyncedLyrics

pub fn line( &mut self, line: LineTag, ) -> Result<&mut SyncedLyrics, TimestampError>

Adds a line to the lyrics.

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

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

Adds multiple lines to the lyrics.

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

pub fn try_new(tags: Vec<LineTag>) -> Result<SyncedLyrics, TimestampError>

Creates an empty synced lyrics struct with some timed tags.

Returns an error if the timestamp order is not correct.

pub fn serialize(self) -> String

Serialize the struct to LRC format.

NOTE: This method may not always produce the same output as the input parsed to create the data structure. For instance, the original placement of ID tags and comments is not preserved, and the offset tag is omitted as it is applied by the parser.

It should, however, always produce the same result for input serialized from its output.

For instance:

let input = include_str!("../assets/example.lrc");
let parsed = SyncedLyrics::parse(&input).unwrap();
let parsed_twice = SyncedLyrics::parse(&parsed.clone().serialize())
    .unwrap()
    .serialize();
assert_eq!(parsed.serialize(), parsed_twice);

pub fn parse(input: &str) -> Result<SyncedLyrics, Error>

Parses LRC lyrics data.

§Examples

Parse some lyrics

let content = "[ti:My awesome song]
[00:02.50] La la la
[00:05.10] <00:05.10> La la la <00:06.30> la la la";
let lyrics = SyncedLyrics::parse(content).unwrap();

Parser fails to parse content with invalid ID tags

let content = "[fun:I am an invalid ID tag]";
assert_eq!(
    SyncedLyrics::parse(content),
    Err(Error::UnknownKey { key: "fun".to_string() })
);

Parser fails to parse content with invalid timestamp order

let content = "[00:02.10] First line
[00:01.90] My timestamp is wrong!";
assert_eq!(
    SyncedLyrics::parse(content),
    Err(Error::Timestamp(lrc_rs::TimestampError {
        line: Some(1),
        segment: None,
        expected: lrc_rs::TimestampConstraint::GreaterThan(Duration::from_secs_f32(2.10)),
        actual: Duration::from_secs_f32(1.9),
    }))
);

Trait Implementations§

§

impl Clone for SyncedLyrics

§

fn clone(&self) -> SyncedLyrics

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 SyncedLyrics

§

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

Formats the value using the given formatter. Read more
§

impl Default for SyncedLyrics

§

fn default() -> SyncedLyrics

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

impl Eq for SyncedLyrics

§

impl Hash for SyncedLyrics

§

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 Ord for SyncedLyrics

§

fn cmp(&self, other: &SyncedLyrics) -> 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 SyncedLyrics

§

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

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

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

Inequality operator !=. Read more
§

impl PartialOrd for SyncedLyrics

§

fn partial_cmp(&self, other: &SyncedLyrics) -> 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 SyncedLyrics

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