Create info method in BlockType.

This commit is contained in:
Pedro de Oliveira 2023-04-28 11:05:33 +01:00
parent b48fa03eaa
commit b8dc6b10bb
1 changed files with 45 additions and 39 deletions

View File

@ -40,6 +40,50 @@ pub enum BlockType {
RepeatEnd,
}
impl BlockType {
pub fn info(&self) {
match self {
BlockType::Terminator => println!("Terminator"),
BlockType::SoundData {
sample_rate,
codec,
data,
} => {
println!(
"Sound data: sample rate = {}, codec = {:?}, size = {}",
sample_rate,
codec,
data.len()
)
}
BlockType::SoundDataContinuation { data } => {
println!("Sound data continuation: size = {}", data.len())
}
BlockType::Silence {
length,
sample_rate,
} => {
println!(
"Silence: length = {}, sample rate = {}",
length, sample_rate
)
}
BlockType::Marker { value } => {
println!("Marker: value = {}", value)
}
BlockType::Text { data } => {
println!("Text: size = {}", data.len())
}
BlockType::RepeatStart { count } => {
println!("Repeat: repetitions = {}", count)
}
BlockType::RepeatEnd => {
println!("End repeat")
}
}
}
}
#[derive(Debug)]
pub struct Version {
major: u8,
@ -192,45 +236,7 @@ fn main() {
);
for (i, block) in voc.blocks.iter().enumerate() {
print!("#{} - ", i);
match block {
BlockType::Terminator => println!("Terminator"),
BlockType::SoundData {
sample_rate,
codec,
data,
} => {
println!(
"Sound data: sample rate = {}, codec = {:?}, size = {}",
sample_rate,
codec,
data.len()
)
}
BlockType::SoundDataContinuation { data } => {
println!("Sound data continuation: size = {}", data.len())
}
BlockType::Silence {
length,
sample_rate,
} => {
println!(
"Silence: length = {}, sample rate = {}",
length, sample_rate
)
}
BlockType::Marker { value } => {
println!("Marker: value = {}", value)
}
BlockType::Text { data } => {
println!("Text: size = {}", data.len())
}
BlockType::RepeatStart { count } => {
println!("Repeat: repetitions = {}", count)
}
BlockType::RepeatEnd => {
println!("End repeat")
}
}
block.info();
}
}
Err(err) => {