pub struct BankView<'a> { /* private fields */ }Expand description
An immutable view to a data bank in a MIDAS file.
Implementations§
Source§impl<'a> BankView<'a>
impl<'a> BankView<'a>
Sourcepub fn name(&self) -> [u8; 4]
pub fn name(&self) -> [u8; 4]
Returns the name of the data bank.
Examples found in repository?
examples/single_bank.rs (line 14)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let contents = std::fs::read("example.mid")?;
3 // Note that if your MIDAS file is compressed, you will need to decompress
4 // its contents (using an external crate) before parsing it.
5 let file_view = midasio::FileView::try_from_bytes(&contents)?;
6
7 // Iterate only through events with an ID of 1
8 for event in file_view.into_iter().filter(|event| event.id() == 1) {
9 // Lets assume that these events have multiple data banks, but they are
10 // guaranteed to have a single bank with the name "TRGB" (which is the
11 // one we are interested in)
12 let [trg_bank] = event
13 .into_iter()
14 .filter(|bank| bank.name() == *b"TRGB")
15 .collect::<Vec<_>>()[..]
16 else {
17 unreachable!();
18 };
19 // You can now access the data in the bank
20 let _trg_data = trg_bank.data();
21 }
22
23 Ok(())
24}Sourcepub fn data(&self) -> &'a [u8] ⓘ
pub fn data(&self) -> &'a [u8] ⓘ
Returns the data stored in the data bank.
Examples found in repository?
examples/single_bank.rs (line 20)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let contents = std::fs::read("example.mid")?;
3 // Note that if your MIDAS file is compressed, you will need to decompress
4 // its contents (using an external crate) before parsing it.
5 let file_view = midasio::FileView::try_from_bytes(&contents)?;
6
7 // Iterate only through events with an ID of 1
8 for event in file_view.into_iter().filter(|event| event.id() == 1) {
9 // Lets assume that these events have multiple data banks, but they are
10 // guaranteed to have a single bank with the name "TRGB" (which is the
11 // one we are interested in)
12 let [trg_bank] = event
13 .into_iter()
14 .filter(|bank| bank.name() == *b"TRGB")
15 .collect::<Vec<_>>()[..]
16 else {
17 unreachable!();
18 };
19 // You can now access the data in the bank
20 let _trg_data = trg_bank.data();
21 }
22
23 Ok(())
24}Trait Implementations§
impl<'a> Copy for BankView<'a>
Auto Trait Implementations§
impl<'a> Freeze for BankView<'a>
impl<'a> RefUnwindSafe for BankView<'a>
impl<'a> Send for BankView<'a>
impl<'a> Sync for BankView<'a>
impl<'a> Unpin for BankView<'a>
impl<'a> UnwindSafe for BankView<'a>
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