pub struct CDText<'data> { /* private fields */ }Expand description
Main parser structure.
Implementations§
Source§impl<'data> CDText<'data>
impl<'data> CDText<'data>
Sourcepub fn from_data_with_length(data: &'data [u8]) -> Self
pub fn from_data_with_length(data: &'data [u8]) -> Self
Creates a parser from data, assuming that first 4 bytes are used for service info. First two bytes are the data length minus two.
Examples found in repository?
examples/parse.rs (line 19)
3fn main() {
4 let Some(filename) = std::env::args().skip(1).next() else {
5 eprintln!("No filename provided!");
6
7 std::process::exit(1);
8 };
9
10 let data = match std::fs::read(filename) {
11 Ok(data) => data,
12 Err(e) => {
13 eprintln!("Failed to read the file: {e:?}");
14
15 std::process::exit(1);
16 }
17 };
18
19 let cdtext = CDText::from_data_with_length(&data);
20
21 let data: Vec<cdtext::CDTextEntry> = cdtext.parse();
22
23 for i in data {
24 let displayable_track = match i.track_number {
25 cdtext::CDTextTrackNumber::WholeAlbum => {
26 format!("Album")
27 },
28 cdtext::CDTextTrackNumber::Track(nr) => {
29 format!("Track #{nr}")
30 },
31 };
32
33 println!("{displayable_track}: {:?}: {:?}", i.entry_type, i.data);
34 }
35}Sourcepub fn iter_pack_chunks(&self) -> impl Iterator<Item = Option<CDTextPack>>
pub fn iter_pack_chunks(&self) -> impl Iterator<Item = Option<CDTextPack>>
Wrapper method.
Sourcepub fn parse(&self) -> Vec<CDTextEntry>
pub fn parse(&self) -> Vec<CDTextEntry>
Parses all the entries from the data and returns a Vec with parsed entries.
Examples found in repository?
examples/parse.rs (line 21)
3fn main() {
4 let Some(filename) = std::env::args().skip(1).next() else {
5 eprintln!("No filename provided!");
6
7 std::process::exit(1);
8 };
9
10 let data = match std::fs::read(filename) {
11 Ok(data) => data,
12 Err(e) => {
13 eprintln!("Failed to read the file: {e:?}");
14
15 std::process::exit(1);
16 }
17 };
18
19 let cdtext = CDText::from_data_with_length(&data);
20
21 let data: Vec<cdtext::CDTextEntry> = cdtext.parse();
22
23 for i in data {
24 let displayable_track = match i.track_number {
25 cdtext::CDTextTrackNumber::WholeAlbum => {
26 format!("Album")
27 },
28 cdtext::CDTextTrackNumber::Track(nr) => {
29 format!("Track #{nr}")
30 },
31 };
32
33 println!("{displayable_track}: {:?}: {:?}", i.entry_type, i.data);
34 }
35}Auto Trait Implementations§
impl<'data> Freeze for CDText<'data>
impl<'data> RefUnwindSafe for CDText<'data>
impl<'data> Send for CDText<'data>
impl<'data> Sync for CDText<'data>
impl<'data> Unpin for CDText<'data>
impl<'data> UnwindSafe for CDText<'data>
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
Mutably borrows from an owned value. Read more