Struct fsbex::Bank

source ·
pub struct Bank<R: Read> { /* private fields */ }
Expand description

An FMOD sound bank.

The FMOD sound bank is a container format that can contain multiple streams/songs. All streams have the same AudioFormat. Decoding and encoding is performed lazily.

Examples

Reading from a slice of bytes:

use fsbex::Bank;
use std::error::Error;

fn read_from_slice(bytes: &[u8]) -> Result<Bank<&[u8]>, Box<dyn Error>> {
    let bank = Bank::new(bytes)?;
    Ok(bank)
}

Reading from a File using a Path:

use fsbex::Bank;
use std::{error::Error, fs::File, io::BufReader, path::Path};

fn read_from_file<P: AsRef<Path>>(path: P) -> Result<Bank<BufReader<File>>, Box<dyn Error>> {
    let file = File::open(path)?;
    let reader = BufReader::new(file);
    let bank = Bank::new(reader)?;
    Ok(bank)
}

Implementations§

source§

impl<R: Read> Bank<R>

source

pub fn new(source: R) -> Result<Self, DecodeError>

Creates a new Bank<R> by parsing from an I/O stream.

Contents are parsed directly from the stream without being buffered in memory. When reading from a source where small, repeated read calls are inefficient, such as a File, buffering with something like BufReader is recommended.

Errors

This function returns an error if parsing of the sound bank’s file header failed. See DecodeError for more information.

source

pub fn format(&self) -> AudioFormat

Returns the audio format of streams in the sound bank.

See AudioFormat for the list of known formats.

source

pub fn num_streams(&self) -> NonZeroU32

Returns the number of streams in the sound bank.

source

pub fn read_streams<F, E>(self, f: F) -> Result<(), LazyStreamError<E>>where F: Fn(LazyStream<'_, R>) -> Result<(), E>,

Sequentially reads streams from the sound bank, consuming this Bank<R>. Streams can be accessed within the function f as they are read. See LazyStream for more information.

Errors

This function returns an error if:

  • an error was returned from f
  • the underlying reader failed to advance to the next stream

See LazyStreamError for more information.

Trait Implementations§

source§

impl<R: Clone + Read> Clone for Bank<R>

source§

fn clone(&self) -> Bank<R>

Returns a copy 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<R: Debug + Read> Debug for Bank<R>

source§

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

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

impl<R: Read> From<Bank<R>> for StreamIntoIter<R>

source§

fn from(value: Bank<R>) -> Self

Converts to this type from the input type.
source§

impl<R: Read> IntoIterator for Bank<R>

§

type IntoIter = StreamIntoIter<R>

Which kind of iterator are we turning this into?
§

type Item = Stream

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<R: PartialEq + Read> PartialEq<Bank<R>> for Bank<R>

source§

fn eq(&self, other: &Bank<R>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: Eq + Read> Eq for Bank<R>

source§

impl<R: Read> StructuralEq for Bank<R>

source§

impl<R: Read> StructuralPartialEq for Bank<R>

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for Bank<R>where R: RefUnwindSafe,

§

impl<R> Send for Bank<R>where R: Send,

§

impl<R> Sync for Bank<R>where R: Sync,

§

impl<R> Unpin for Bank<R>where R: Unpin,

§

impl<R> UnwindSafe for Bank<R>where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.