Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for v0.3.0 #5

Merged
merged 6 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- uses: actions/[email protected]
- uses: actions/setup-dotnet@v1
with:
dotnet-version: "5.0.x"
dotnet-version: "8.0.x"
include-prerelease: true
- uses: actions-rs/toolchain@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions rnet-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "rnet-example"
version = "0.2.0"
version = "0.3.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]

[dependencies]
rnet = { version = "0.2.0", path = "../rnet" }
rnet = { version = "0.3.0", path = "../rnet" }
linkme = "0.2.7"
4 changes: 2 additions & 2 deletions rnet-gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rnet-gen"
version = "0.2.0"
version = "0.3.0"
edition = "2018"
readme = "../README.md"
license = "MIT OR Apache-2.0"
Expand All @@ -11,7 +11,7 @@ description = "Generator for rnet."

[dependencies]
libloading = "0.7.1"
rnet = { version = "0.2.0", path = "../rnet" }
rnet = { version = "0.3.0", path = "../rnet" }
structopt = "0.3"
anyhow = "1.0"
heck = "0.3.3"
5 changes: 2 additions & 3 deletions rnet-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ fn generate_csharp_code(_opt: &Opt, name: &str, desc: LibDesc) -> anyhow::Result
let common = COMMON
.replace("__ClassName__", &name.to_camel_case())
.replace("\"__LibName__\"", &format!("{:?}", name));
let mut parts = common.splitn(2, "// __Remainder__");
let prefix = parts.next().unwrap();
let suffix = parts.next().unwrap();

let (prefix, suffix) = common.split_once("// __Remainder__").unwrap();

let mut extra_items = Vec::new();
let mut used_tuple_keys = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion rnet-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rnet-macros"
version = "0.2.0"
version = "0.3.0"
edition = "2018"
readme = "../README.md"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion rnet-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn net_impl(attr: TokenStream, item: TokenStream) -> Result<TokenStream2> {
lifetime: Lifetime::new("'net", Span::call_site()),
};
let local_arg_types = arg_types.iter().cloned().map(|mut arg| {
lifetime_injector.visit_type_mut(&mut *arg);
lifetime_injector.visit_type_mut(&mut arg);
arg
});

Expand Down
2 changes: 1 addition & 1 deletion rnet-tests-cs/RnetTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>RnetTests</RootNamespace>
<IsPackable>false</IsPackable>
<Platforms>x64</Platforms>
Expand Down
4 changes: 2 additions & 2 deletions rnet-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rnet-tests"
version = "0.2.0"
version = "0.3.0"
edition = "2018"
readme = "../README.md"
license = "MIT OR Apache-2.0"
Expand All @@ -12,5 +12,5 @@ description = "Tests for rnet."
crate-type = ["cdylib"]

[dependencies]
rnet = { version = "0.2.0", path = "../rnet" }
rnet = { version = "0.3.0", path = "../rnet" }
linkme = "0.2.7"
4 changes: 2 additions & 2 deletions rnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rnet"
version = "0.2.0"
version = "0.3.0"
edition = "2018"
readme = "../README.md"
license = "MIT OR Apache-2.0"
Expand All @@ -11,6 +11,6 @@ description = "Easily call into Rust from C# or other .net langauges."

[dependencies]
linkme = "0.2.7"
rnet-macros = { version = "0.2.0", path = "../rnet-macros" }
rnet-macros = { version = "0.3.0", path = "../rnet-macros" }
uuid = { version = "0.8.2", optional = true }
chrono = { version = "0.4.19", optional = true }
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
2 changes: 1 addition & 1 deletion rnet/src/std_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ unsafe impl<T: ToNet> ToNet for Box<T> {
}
}

fn int_type_id<T: 'static>() -> u64 {
fn int_type_id<T: 'static>() -> u128 {
unsafe { std::mem::transmute(TypeId::of::<T>()) }
}

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
2 changes: 1 addition & 1 deletion rnet/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Default for RawSlice {
pub struct RawOpaqueHandle {
pub ptr: *mut (),
pub drop_fn: Option<unsafe extern "C" fn(ptr: *mut ())>,
pub type_id: u64,
pub type_id: u128,
}

impl Default for RawOpaqueHandle {
Expand Down
Loading