pub trait WriteSamples: Write {
// Provided methods
fn write_sample<T: BytesSample>(&mut self, sample: &T) -> Result<()> { ... }
fn write_number<T: BytesSample>(
&mut self,
value: T::NumericType,
) -> Result<()> { ... }
fn write_converted<T: RawSample + BytesSample, U: FloatCore + ToPrimitive>(
&mut self,
value: U,
) -> Result<bool> { ... }
fn write_all_samples<T: BytesSample>(&mut self, samples: &[T]) -> Result<()> { ... }
fn write_all_numbers<T: BytesSample>(
&mut self,
values: &[T::NumericType],
) -> Result<()> { ... }
fn write_all_converted<T: RawSample + BytesSample, U: FloatCore + ToPrimitive>(
&mut self,
values: &[U],
) -> Result<usize> { ... }
}Expand description
A trait that extends std::io::Write with methods for writing samples directly.
Provided Methods§
Sourcefn write_sample<T: BytesSample>(&mut self, sample: &T) -> Result<()>
fn write_sample<T: BytesSample>(&mut self, sample: &T) -> Result<()>
Write a single sample to the underlying writer.
This method takes a reference to a sample of type T,
gets its raw byte representation using the as_slice method,
and writes it to the underlying writer.
§Type Parameters
T: A type implementing theBytesSampletrait, defining the format of the sample to write.
§Returns
io::Result<()>: Ok(()) if the sample was written successfully.
§Errors
This function will return an error if:
- The underlying writer returns an error.
Sourcefn write_number<T: BytesSample>(&mut self, value: T::NumericType) -> Result<()>
fn write_number<T: BytesSample>(&mut self, value: T::NumericType) -> Result<()>
Write a single sample from a numeric type to the underlying writer.
This method takes a sample represented by its NumericType,
converts it to a raw byte representation using the provided T,
and writes it to the underlying writer.
§Type Parameters
T: A type implementing theBytesSampletrait, defining the format of the sample to write.
§Arguments
value: The sample to write.
§Returns
io::Result<()>: Ok(()) if the sample was written successfully.
§Errors
This function will return an error if:
- The underlying writer returns an error.
Sourcefn write_converted<T: RawSample + BytesSample, U: FloatCore + ToPrimitive>(
&mut self,
value: U,
) -> Result<bool>
fn write_converted<T: RawSample + BytesSample, U: FloatCore + ToPrimitive>( &mut self, value: U, ) -> Result<bool>
Write a single converted sample to the underlying writer.
This method takes a floating-point sample of type U, converts it to
the raw byte representation of type T and then writes it to the underlying writer.
§Type Parameters
T: A type implementing bothRawSampleandBytesSample, defining the format of the sample to write.U: A floating-point type implementingFloatCoreandToPrimitive, representing the sample to write.
§Arguments
value: The sample to write.
§Returns
io::Result<bool>: Ok(true) if the value was clipped during conversion, Ok(false) otherwise.
§Errors
This function will return an error if:
- The underlying writer returns an error.
Sourcefn write_all_samples<T: BytesSample>(&mut self, samples: &[T]) -> Result<()>
fn write_all_samples<T: BytesSample>(&mut self, samples: &[T]) -> Result<()>
Write multiple samples to the underlying writer.
This method takes a slice of samples, gets the raw byte representation of each sample, and then writes it to the underlying writer.
§Type Parameters
T: A type implementing theBytesSampletrait, defining the format of the samples to write.
§Arguments
samples: The samples to write.
§Returns
io::Result<()>: Ok(()) if all samples were written successfully.
§Errors
This function will return an error if:
- The underlying writer returns an error.
Sourcefn write_all_numbers<T: BytesSample>(
&mut self,
values: &[T::NumericType],
) -> Result<()>
fn write_all_numbers<T: BytesSample>( &mut self, values: &[T::NumericType], ) -> Result<()>
Write multiple samples from a numeric slice to the underlying writer.
This method takes a slice of samples represented by their NumericType,
converts each sample to its raw byte representation using the provided T,
and writes them to the underlying writer.
§Type Parameters
T: A type implementing theBytesSampletrait, defining the format of the samples to write.
§Arguments
values: The samples to write.
§Returns
io::Result<()>: Ok(()) if all samples were written successfully.
§Errors
This function will return an error if:
- The underlying writer returns an error.
Sourcefn write_all_converted<T: RawSample + BytesSample, U: FloatCore + ToPrimitive>(
&mut self,
values: &[U],
) -> Result<usize>
fn write_all_converted<T: RawSample + BytesSample, U: FloatCore + ToPrimitive>( &mut self, values: &[U], ) -> Result<usize>
Write multiple converted samples from a float slice to the underlying writer.
This method takes a slice of floating-point samples of type U, converts each sample
to its raw byte representation of type T, and then writes them to the underlying writer.
§Type Parameters
T: A type implementing bothRawSampleandBytesSample, defining the format of the samples to write.U: A floating-point type implementingFloatCoreandToPrimitive, representing the samples to write.
§Arguments
values: The samples to write.
§Returns
io::Result<usize>: The number of samples that were clipped during conversion.
§Errors
This function will return an error if:
- The underlying writer returns an error.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".