From 20f5884b50abb310154d846534f2e4f7c4dbb717 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 8 Oct 2019 02:50:18 +0200 Subject: [PATCH] update --- src/main.rs | 55 +++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/main.rs b/src/main.rs index 84f16385..9ac1aa69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,28 +38,20 @@ mod channel { } } - pub struct ChannelDefaults; - impl ChannelDefaults { - pub fn method1(this: &mut Channel) { - unsafe { Channel__Channel__method1(this) } - } - } - - pub trait ChannelOverrides: AsChannel { - fn extender(&self) -> &ChannelExtender; - fn extender_mut(&mut self) -> &mut ChannelExtender; - - fn method1(&mut self) { - ChannelDefaults::method1(self.extender_mut().as_mut()) - } - fn method2(&self) -> i32; - } - pub trait AsChannel { fn as_channel(&self) -> &Channel; fn as_channel_mut(&mut self) -> &mut Channel; } + impl AsChannel for Channel { + fn as_channel(&self) -> &Channel { + self + } + fn as_channel_mut(&mut self) -> &mut Channel { + self + } + } + impl AsChannel for ChannelExtender { fn as_channel(&self) -> &Channel { &self.cxx_channel @@ -81,6 +73,23 @@ mod channel { } } + pub struct ChannelDefaults; + impl ChannelDefaults { + pub fn method1(channel: &mut Channel) { + unsafe { Channel__Channel__method1(channel) } + } + } + + pub trait ChannelOverrides: AsChannel { + fn extender(&self) -> &ChannelExtender; + fn extender_mut(&mut self) -> &mut ChannelExtender; + + fn method1(&mut self) { + ChannelDefaults::method1(self.as_channel_mut()) + } + fn method2(&self) -> i32; + } + pub struct ChannelExtender { cxx_channel: Channel, extender_offset: usize, @@ -170,18 +179,6 @@ mod channel { std::mem::transmute((embedder, vtable)) } } - - impl std::convert::AsRef for ChannelExtender { - fn as_ref(&self) -> &Channel { - &self.cxx_channel - } - } - - impl std::convert::AsMut for ChannelExtender { - fn as_mut(&mut self) -> &mut Channel { - &mut self.cxx_channel - } - } } mod util {