Struct BankView

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

Source

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

pub fn data_type(&self) -> DataType

Returns the data type of the data bank.

Source

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§

Source§

impl<'a> Clone for BankView<'a>

Source§

fn clone(&self) -> BankView<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for BankView<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.