Skip to content

Commit

Permalink
defef
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed May 9, 2024
1 parent 604502c commit 9bbc0a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
11 changes: 3 additions & 8 deletions crates/libs/core/src/ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ use super::*;
#[repr(transparent)]
pub struct Ref<'a, T: Type<T>>(T::Abi, std::marker::PhantomData<&'a T>);

impl<'a, T: Type<T>> Ref<'a, T> {
/// Reads the borrowed value.
pub fn read(&self) -> &T::Default {
impl<'a, T: Type<T>> std::ops::Deref for Ref<'a, T> {
type Target = T::Default;
fn deref(&self) -> &Self::Target {
unsafe { std::mem::transmute(&self.0) }
}

/// Clones the borrowed value.
pub fn ok(&self) -> Result<T> {
T::from_default(self.read())
}
}
12 changes: 6 additions & 6 deletions crates/tests/interface_core/tests/ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ impl ITest_Impl for Test {
output.write(input).into()
}
unsafe fn hstring(&self, input: Ref<HSTRING>, output: RefMut<HSTRING>) -> HRESULT {
output.write(input.read().clone()).into()
output.write(input.clone()).into()
}
unsafe fn interface(&self, input: Ref<ITest>, output: RefMut<ITest>) -> HRESULT {
output.write(input.read().clone()).into()
output.write(input.clone()).into()
}
unsafe fn required_input(&self, input: Ref<ITest>, output: RefMut<ITest>) -> HRESULT {
if input.read().is_none() {
if input.is_none() {
E_INVALIDARG
} else {
self.interface(input, output)
Expand All @@ -56,13 +56,13 @@ impl ITest_Impl for Test {
output.write(input)
}
unsafe fn result_hstring(&self, input: Ref<HSTRING>, output: RefMut<HSTRING>) -> Result<()> {
output.write(input.read().clone())
output.write(input.clone())
}
unsafe fn result_interface(&self, input: Ref<ITest>, output: RefMut<ITest>) -> Result<()> {
output.write(input.read().clone())
output.write(input.clone())
}
unsafe fn result_required_input(&self, input: Ref<ITest>, output: RefMut<ITest>) -> Result<()> {
if input.read().is_none() {
if input.is_none() {
E_INVALIDARG.ok()
} else {
self.result_interface(input, output)
Expand Down

0 comments on commit 9bbc0a9

Please sign in to comment.