CDText

Struct CDText 

Source
pub struct CDText<'data> { /* private fields */ }
Expand description

Main parser structure.

Implementations§

Source§

impl<'data> CDText<'data>

Source

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}
Source

pub fn from_data(data: &'data [u8]) -> Self

Creates a parser from data.

Source

pub fn iter_pack_chunks(&self) -> impl Iterator<Item = Option<CDTextPack>>

Wrapper method.

Source

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.