Skip to content

Commit

Permalink
rnet: Fix clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Castello <[email protected]>
  • Loading branch information
microhobby committed Nov 15, 2023
1 parent 031a69d commit 9315dc9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rnet/src/from_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
Net,
};

/// # Safety
/// This trait is implemented for Rust types which can be received
/// from .net code.
pub unsafe trait FromNet: Net + for<'a> FromNetArg<'a> {
Expand All @@ -18,6 +19,7 @@ pub unsafe trait FromNet: Net + for<'a> FromNetArg<'a> {
unsafe fn from_raw(arg: Self::Raw) -> Self;
}

/// # Safety
/// This trait is implemented for Rust types which can be used as arguments
/// to exported functions. This is a superset of types which implement
/// `FromNet`, and allows passing types with lifetime arguments, like `&str`.
Expand All @@ -37,6 +39,7 @@ unsafe impl<'a, T: FromNet> FromNetArg<'a> for T {
}
}

/// # Safety
/// This trait is implemented for Rust types which can be returned from
/// .net delegates. This is a superset of types which implement `FromNet`,
/// and allows returning eg. the unit `()` type, whose .net equivalent
Expand Down
1 change: 1 addition & 0 deletions rnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn none_ty(_ctx: &mut GeneratorContext) -> Option<Box<str>> {
None
}

/// # Safety
/// This trait is implemented for Rust types which have
/// an equivalent type within .net.
pub unsafe trait Net: 'static {
Expand Down
14 changes: 13 additions & 1 deletion rnet/src/to_net.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::types::{GeneratorContext, TypeDesc};
use crate::{none_ty, Net};

/// # Safety
/// This trait is implemented for Rust types which can be sent
/// to .net code.
pub unsafe trait ToNet: Net + ToNetReturn {
Expand All @@ -15,6 +16,7 @@ pub unsafe trait ToNet: Net + ToNetReturn {
fn gen_marshal(ctx: &mut GeneratorContext, arg: &str) -> Box<str>;
}

/// # Safety
/// This trait is implemented for Rust types which can be used as arguments
/// to .net delegates. This is a superset of types which implement
/// `ToNet`, and allows passing types with lifetime arguments, like `&str`.
Expand All @@ -29,13 +31,18 @@ pub unsafe trait ToNetArg: Sized {
}
}

unsafe impl<'a, T: ToNet> ToNetArg for T {
/// # Safety
/// This trait is implemented for Rust types which can be used as arguments
/// to .net delegates. This is a superset of types which implement
/// `ToNet`, and allows passing types with lifetime arguments, like `&str`.
unsafe impl<T: ToNet> ToNetArg for T {
type Owned = Self;
fn to_owned(self) -> Self::Owned {
self
}
}

/// # Safety
/// This trait is implemented for Rust types which can be returned from
/// exported functions. This is a superset of types which implement `ToNet`,
/// and allows returning eg. the unit `()` type, whose .net equivalent
Expand All @@ -49,6 +56,11 @@ pub unsafe trait ToNetReturn {
fn to_raw_return(self) -> Self::RawReturn;
}

/// # Safety
/// This trait is implemented for Rust types which can be returned from
/// exported functions. This is a superset of types which implement `ToNet`,
/// and allows returning eg. the unit `()` type, whose .net equivalent
/// `void` cannot be used as a normal type.
unsafe impl<T: ToNet> ToNetReturn for T {
const RETURN_DESC: &'static TypeDesc = T::TO_DESC;
type RawReturn = <Self as Net>::Raw;
Expand Down

0 comments on commit 9315dc9

Please sign in to comment.