Merge pull request #34 from hako/csharp-to-rust

Add C# to Rust example
This commit is contained in:
Alex Crichton
2019-11-19 09:04:39 -06:00
committed by GitHub
5 changed files with 39 additions and 0 deletions

3
csharp-to-rust/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock

View File

@@ -0,0 +1,8 @@
[package]
name = "csharp-to-rust"
version = "0.1.0"
authors = ["Wesley Hill <wesley@hakobaito.co.uk>"]
[lib]
name = "double_input"
crate-type = ["cdylib"]

9
csharp-to-rust/Makefile Normal file
View File

@@ -0,0 +1,9 @@
all: target/debug/libdouble_input
csc src/double.cs
mono ./double.exe
target/debug/libdouble_input: src/lib.rs Cargo.toml
rustc --crate-name double_input src/lib.rs --crate-type cdylib -o libdouble_input
clean:
rm -rf target double.exe

View File

@@ -0,0 +1,15 @@
using System;
using System.Runtime.InteropServices;
namespace DoubleClass {
class Double {
[DllImport ("libdouble_input")]
public static extern int double_input (int input);
public static void Main (string[] args) {
Console.WriteLine (double_input (2));
}
}
}

View File

@@ -0,0 +1,4 @@
#[no_mangle]
pub extern fn double_input(input: i32) -> i32 {
input * 2
}