Skip to content

Commit

Permalink
Remove the get_ prefix of methods (RustAudio#151)
Browse files Browse the repository at this point in the history
* Remove the `get_` prefix of methods

* Fix overlooks
  • Loading branch information
tomaka authored Oct 11, 2017
1 parent 35d9201 commit cdcef96
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/beep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl Executor for MyExecutor {
}

fn main() {
let endpoint = cpal::get_default_endpoint().expect("Failed to get default endpoint");
let format = endpoint.get_supported_formats_list().unwrap().next().expect("Failed to get endpoint format");
let endpoint = cpal::default_endpoint().expect("Failed to get default endpoint");
let format = endpoint.supported_formats().unwrap().next().expect("Failed to get endpoint format");

let event_loop = cpal::EventLoop::new();
let executor = Arc::new(MyExecutor);
Expand Down
6 changes: 3 additions & 3 deletions examples/enumerate.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extern crate cpal;

fn main() {
let endpoints = cpal::get_endpoints_list();
let endpoints = cpal::endpoints();

println!("Endpoints: ");
for (endpoint_index, endpoint) in endpoints.enumerate() {
println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.get_name());
println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.name());

let formats = match endpoint.get_supported_formats_list() {
let formats = match endpoint.supported_formats() {
Ok(f) => f,
Err(e) => { println!("Error: {:?}", e); continue; }
};
Expand Down
36 changes: 33 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,64 @@ impl Iterator for EndpointsIterator {

/// Return an iterator to the list of formats that are supported by the system.
#[inline]
pub fn endpoints() -> EndpointsIterator {
EndpointsIterator(Default::default())
}

/// Deprecated. Use `endpoints()` instead.
#[inline]
#[deprecated]
pub fn get_endpoints_list() -> EndpointsIterator {
EndpointsIterator(Default::default())
}

/// Return the default endpoint, or `None` if no device is available.
#[inline]
pub fn get_default_endpoint() -> Option<Endpoint> {
pub fn default_endpoint() -> Option<Endpoint> {
cpal_impl::get_default_endpoint().map(Endpoint)
}

/// Deprecated. Use `default_endpoint()` instead.
#[inline]
#[deprecated]
pub fn get_default_endpoint() -> Option<Endpoint> {
default_endpoint()
}

/// An opaque type that identifies an end point.
#[derive(Clone, PartialEq, Eq)]
pub struct Endpoint(cpal_impl::Endpoint);

impl Endpoint {
/// Returns an iterator that produces the list of formats that are supported by the backend.
#[inline]
pub fn supported_formats(&self) -> Result<SupportedFormatsIterator,
FormatsEnumerationError>
{
Ok(SupportedFormatsIterator(try!(self.0.get_supported_formats_list())))
}

/// Deprecated. Use `supported_formats` instead.
#[inline]
#[deprecated]
pub fn get_supported_formats_list(&self) -> Result<SupportedFormatsIterator,
FormatsEnumerationError>
{
Ok(SupportedFormatsIterator(try!(self.0.get_supported_formats_list())))
self.supported_formats()
}

/// Returns the name of the endpoint.
#[inline]
pub fn get_name(&self) -> String {
pub fn name(&self) -> String {
self.0.get_name()
}

/// Deprecated. Use `name()` instead.
#[deprecated]
#[inline]
pub fn get_name(&self) -> String {
self.name()
}
}

/// Number of channels.
Expand Down
10 changes: 9 additions & 1 deletion src/samples_formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ pub enum SampleFormat {
impl SampleFormat {
/// Returns the size in bytes of a sample of this format.
#[inline]
pub fn get_sample_size(&self) -> usize {
pub fn sample_size(&self) -> usize {
match self {
&SampleFormat::I16 => mem::size_of::<i16>(),
&SampleFormat::U16 => mem::size_of::<u16>(),
&SampleFormat::F32 => mem::size_of::<f32>(),
}
}

/// Deprecated. Use `sample_size` instead.
#[inline]
#[deprecated]
pub fn get_sample_size(&self) -> usize {
self.sample_size()
}
}

/// Trait for containers that contain PCM data.
pub unsafe trait Sample: Copy + Clone {
/// Returns the `SampleFormat` corresponding to this data type.
// TODO: rename to `format()`. Requires a breaking change.
fn get_format() -> SampleFormat;
}

Expand Down

0 comments on commit cdcef96

Please sign in to comment.