Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
934e36ba
Commit
934e36ba
authored
Oct 16, 2019
by
Sébastien Blin
Committed by
Adrien Béraud
Oct 22, 2019
Browse files
Options
Downloads
Patches
Plain Diff
rust: ffi POC
parent
2e47b9ba
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
rust/.gitignore
+2
-0
2 additions, 0 deletions
rust/.gitignore
rust/Cargo.toml
+10
-0
10 additions, 0 deletions
rust/Cargo.toml
rust/README.md
+15
-0
15 additions, 0 deletions
rust/README.md
rust/src/lib.rs
+38
-0
38 additions, 0 deletions
rust/src/lib.rs
with
65 additions
and
0 deletions
rust/.gitignore
0 → 100644
+
2
−
0
View file @
934e36ba
*.lock
target
This diff is collapsed.
Click to expand it.
rust/Cargo.toml
0 → 100644
+
10
−
0
View file @
934e36ba
[package]
name
=
"opendht"
version
=
"0.1.0"
authors
=
[
"Sébastien Blin <sebastien.blin@savoirfairelinux.com>"
]
edition
=
"2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc
=
"0.2.0"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rust/README.md
0 → 100644
+
15
−
0
View file @
934e36ba
# Rust bindings for opendht
## Build
Install rust on your system (https://rustup.rs/ is the recommanded way). Once done:
```
cargo build
```
## Run tests
```
cargo test
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rust/src/lib.rs
0 → 100644
+
38
−
0
View file @
934e36ba
extern
crate
libc
;
use
std
::
ffi
::
CString
;
use
libc
::
c_char
;
#[repr(C)]
struct
InfoHash
{}
#[link(name
=
"opendht-c"
)]
extern
{
fn
dht_infohash_print
(
h
:
*
const
InfoHash
)
->
*
mut
c_char
;
fn
dht_infohash_random
(
h
:
*
mut
InfoHash
)
->
();
}
impl
InfoHash
{
pub
fn
new
()
->
Box
<
InfoHash
>
{
let
mut
h
=
Box
::
new
(
InfoHash
{});
unsafe
{
dht_infohash_random
(
&
mut
*
h
);
}
h
}
pub
fn
print
(
&
self
)
->
CString
{
unsafe
{
CString
::
from_raw
(
dht_infohash_print
(
&*
self
))
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
print_random_infohash
()
{
println!
(
"{:?}"
,
InfoHash
::
print
(
&*
InfoHash
::
new
()));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment