Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Use dyn syntax for trait objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
askeksa committed Apr 30, 2019
1 parent af9c8c6 commit f058637
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/dimension_expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl Plugin for DimensionExpander {
}
}

fn get_parameter_object(&mut self) -> Arc<PluginParameters> {
Arc::clone(&self.params) as Arc<PluginParameters>
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters> {
Arc::clone(&self.params) as Arc<dyn PluginParameters>
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/gain_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl Plugin for GainEffect {

// Return the parameter object. This method can be omitted if the
// plugin has no parameters.
fn get_parameter_object(&mut self) -> Arc<PluginParameters> {
Arc::clone(&self.params) as Arc<PluginParameters>
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters> {
Arc::clone(&self.params) as Arc<dyn PluginParameters>
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/transfer_and_smooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl Plugin for MyPlugin {
}

// 5. Return a reference to the parameter struct from get_parameter_object.
fn get_parameter_object(&mut self) -> Arc<PluginParameters> {
Arc::clone(&self.params) as Arc<PluginParameters>
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters> {
Arc::clone(&self.params) as Arc<dyn PluginParameters>
}

fn set_sample_rate(&mut self, sample_rate: f32) {
Expand Down
6 changes: 3 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ impl AEffect {
// Supresses warning about returning a reference to a box
#[allow(unknown_lints)]
#[allow(clippy::borrowed_box)]
pub unsafe fn get_plugin(&mut self) -> &mut Box<Plugin> {
pub unsafe fn get_plugin(&mut self) -> &mut Box<dyn Plugin> {
//FIXME: find a way to do this without resorting to transmuting via a box
&mut *(self.object as *mut Box<Plugin>)
&mut *(self.object as *mut Box<dyn Plugin>)
}

/// Drop the Plugin object. Only works for plugins created using this library.
pub unsafe fn drop_plugin(&mut self) {
drop(Box::from_raw(self.object as *mut Box<Plugin>));
drop(Box::from_raw(self.object as *mut Box<dyn Plugin>));
drop(Box::from_raw(self.user as *mut super::PluginCache));
}

Expand Down
4 changes: 2 additions & 2 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@ impl SendEventBuffer {
/// # }
/// ```
#[inline(always)]
pub fn send_events<T: IntoIterator<Item = U>, U: WriteIntoPlaceholder>(&mut self, events: T, host: &mut Host) {
pub fn send_events<T: IntoIterator<Item = U>, U: WriteIntoPlaceholder>(&mut self, events: T, host: &mut dyn Host) {
self.store_events(events);
host.process_events(self.events());
}

/// Sends events from the host to a plugin.
#[inline(always)]
pub fn send_events_to_plugin<T: IntoIterator<Item = U>, U: WriteIntoPlaceholder>(&mut self, events: T, plugin: &mut Plugin) {
pub fn send_events_to_plugin<T: IntoIterator<Item = U>, U: WriteIntoPlaceholder>(&mut self, events: T, plugin: &mut dyn Plugin) {
self.store_events(events);
plugin.process_events(self.events());
}
Expand Down
8 changes: 4 additions & 4 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use plugin::{Info, PluginParameters};

pub(crate) struct PluginCache {
pub info: Info,
pub params: Arc<PluginParameters>,
pub editor: Option<Box<Editor>>
pub params: Arc<dyn PluginParameters>,
pub editor: Option<Box<dyn Editor>>
}

impl PluginCache {
pub fn new(
info: &Info,
params: Arc<PluginParameters>,
editor: Option<Box<Editor>>
params: Arc<dyn PluginParameters>,
editor: Option<Box<dyn Editor>>
) -> Self {
Self {
info: info.clone(),
Expand Down
4 changes: 2 additions & 2 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ impl Plugin for PluginInstance {
}


fn get_parameter_object(&mut self) -> Arc<PluginParameters> {
Arc::clone(&self.params) as Arc<PluginParameters>
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters> {
Arc::clone(&self.params) as Arc<dyn PluginParameters>
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub fn dispatch(
}

pub fn host_dispatch(
host: &mut Host,
host: &mut dyn Host,
effect: *mut AEffect,
opcode: i32,
index: i32,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub fn main<T: Plugin + Default>(callback: HostCallbackProc) -> *mut AEffect {
_offQualities: 0,
_ioRatio: 0.0,

object: Box::into_raw(Box::new(Box::new(plugin) as Box<Plugin>)) as *mut _,
object: Box::into_raw(Box::new(Box::new(plugin) as Box<dyn Plugin>)) as *mut _,
user: Box::into_raw(Box::new(PluginCache::new(&info, params, editor))) as *mut _,

uniqueId: info.unique_id,
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub trait Plugin {
fn process_events(&mut self, events: &api::Events) {}

/// Get a reference to the shared parameter object.
fn get_parameter_object(&mut self) -> Arc<PluginParameters> {
fn get_parameter_object(&mut self) -> Arc<dyn PluginParameters> {
Arc::new(DummyPluginParameters)
}

Expand Down Expand Up @@ -698,7 +698,7 @@ pub trait Plugin {
///
/// The editor object will typically contain an `Arc` reference to the parameter
/// object through which it can communicate with the audio processing.
fn get_editor(&mut self) -> Option<Box<Editor>> {
fn get_editor(&mut self) -> Option<Box<dyn Editor>> {
None
}
}
Expand Down

0 comments on commit f058637

Please sign in to comment.