Struct LineTag
pub struct LineTag {
pub timestamp: Duration,
pub segments: Vec<SegmentTag>,
}Expand description
A single line in the synced lyrics.
Fields§
§timestamp: DurationThe 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
impl LineTag
pub fn new(timestamp: Duration, content: String) -> 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>
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>
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>
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 Eq for LineTag
§impl LyricsAccess<LineTag> for SyncedLyrics
impl LyricsAccess<LineTag> for SyncedLyrics
§fn is_active(&self, timestamp: Duration) -> bool
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
fn to_unsynced(self) -> String
§fn active_tag_index(&self, timestamp: Duration) -> Option<usize>
fn active_tag_index(&self, timestamp: Duration) -> Option<usize>
§fn active_tag(&self, timestamp: Duration) -> Option<&LineTag>
fn active_tag(&self, timestamp: Duration) -> Option<&LineTag>
§fn check_timestamp_order(&self) -> Result<(), TimestampError>
fn check_timestamp_order(&self) -> Result<(), TimestampError>
§fn is_enhanced_lrc(&self) -> bool
fn is_enhanced_lrc(&self) -> bool
§impl LyricsAccess<SegmentTag> for LineTag
impl LyricsAccess<SegmentTag> for LineTag
§fn is_active(&self, timestamp: Duration) -> bool
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
fn to_unsynced(self) -> String
§fn active_tag_index(&self, timestamp: Duration) -> Option<usize>
fn active_tag_index(&self, timestamp: Duration) -> Option<usize>
§fn active_tag(&self, timestamp: Duration) -> Option<&SegmentTag>
fn active_tag(&self, timestamp: Duration) -> Option<&SegmentTag>
§fn check_timestamp_order(&self) -> Result<(), TimestampError>
fn check_timestamp_order(&self) -> Result<(), TimestampError>
§fn is_enhanced_lrc(&self) -> bool
fn is_enhanced_lrc(&self) -> bool
§impl Ord for LineTag
impl Ord for LineTag
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialOrd for LineTag
impl PartialOrd for LineTag
impl StructuralPartialEq for LineTag
Auto Trait Implementations§
impl Freeze for LineTag
impl RefUnwindSafe for LineTag
impl Send for LineTag
impl Sync for LineTag
impl Unpin for LineTag
impl UnsafeUnpin for LineTag
impl UnwindSafe for LineTag
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().