Add c# to rust example
This commit is contained in:
3
csharp-to-rust/.gitignore
vendored
Normal file
3
csharp-to-rust/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
8
csharp-to-rust/Cargo.toml
Normal file
8
csharp-to-rust/Cargo.toml
Normal 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
9
csharp-to-rust/Makefile
Normal 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
|
||||||
15
csharp-to-rust/src/double.cs
Normal file
15
csharp-to-rust/src/double.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
4
csharp-to-rust/src/lib.rs
Normal file
4
csharp-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#[no_mangle]
|
||||||
|
pub extern fn double_input(input: i32) -> i32 {
|
||||||
|
input * 2
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user