From 3d6c40b9ec10a5885168285f705a706b21e49d29 Mon Sep 17 00:00:00 2001 From: szymonwieloch Date: Fri, 16 Aug 2019 23:26:48 +0200 Subject: [PATCH] Updated readme and marketing. Version bump --- Cargo.toml | 5 +++-- README.md | 30 +++++++++++++++++++++++++++++- src/lib.rs | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e86bf9a..72c2e17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "dlopen" -version = "0.1.7" +version = "0.1.8" +readme = "README.md" authors = ["Szymon Wieloch "] -description = "Library for opening and operating on dynamic link libraries (also known as shared objects or shared libraries)." +description = "Library for opening and operating on dynamic link libraries (also known as shared objects or shared libraries). This is a modern and more flexible alternative to the already existing libraries like libloading or sharedlib" keywords = [ #common functions "dlopen", "dll", "so", "dylib", "shared"] diff --git a/README.md b/README.md index fc45a33..976246f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # rust-dlopen -[![Travis CI][tcii]][tci] [![Appveyor CI][acii]][aci] [![Crates CI][ccii]][cci] [![Codedov CI][vcii]][vci] +[![Travis CI][tcii]][tci] [![Appveyor CI][acii]][aci] [![Crates CI][ccii]][cci] [![Codedov CI][vcii]][vci] [![Docs][dcii]][dci] [tcii]: https://travis-ci.org/szymonwieloch/rust-dlopen.svg?branch=master [tci]: https://travis-ci.org/szymonwieloch/rust-dlopen @@ -10,6 +10,8 @@ [cci]: https://crates.io/crates/dlopen [vcii]: https://codecov.io/api/gh/szymonwieloch/rust-dlopen/branch/master/graph/badge.svg [vci]: https://codecov.io/gh/szymonwieloch/rust-dlopen +[dcii]: https://docs.rs/dlopen/badge.svg +[dci]: https://docs.rs/dlopen # Overview @@ -17,6 +19,31 @@ This library is my effort to make use of dynamic link libraries in Rust simple. Previously existing solutions were either unsafe, provided huge overhead of required writing too much code to achieve simple things. I hope that this library will help you to quickly get what you need and avoid errors. +# Quick example + +```rust +extern crate dlopen; +#[macro_use] +extern crate dlopen_derive; +use dlopen::wrapper::{Container, WrapperApi}; + +#[derive(WrapperApi)] +struct Api<'a> { + example_rust_fun: fn(arg: i32) -> u32, + example_c_fun: unsafe extern "C" fn(), + example_reference: &'a mut i32, +} + +fn main(){ + let mut cont: Container = + unsafe { Container::load("libexample.so") }.expect("Could not open library or load symbols"); + cont.example_rust_fun(5); + unsafe{cont.example_c_fun()}; + *cont.example_reference_mut() = 5; +} +``` + + # Features ## Main features @@ -45,6 +72,7 @@ I hope that this library will help you to quickly get what you need and avoid er | Low-level, unsafe API | Yes | Yes | Yes | | Object-oriented friendly | Yes | **No** | Yes | | Load from the program itself | Yes | **No** | **No** | +| Obtaining address information (dladdr) | Yes | **Unix only** | **no**| ## Safety diff --git a/src/lib.rs b/src/lib.rs index eb988a2..d292df4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,30 @@ This library is an effort to make use of dynamic link libraries in Rust simple. Previously existing solutions were either unsafe, provided huge overhead of required writing too much code to achieve simple things. I hope that this library will help you to quickly get what you need and avoid errors. +# Quick example + +```no_run +extern crate dlopen; +#[macro_use] +extern crate dlopen_derive; +use dlopen::wrapper::{Container, WrapperApi}; + +#[derive(WrapperApi)] +struct Api<'a> { + example_rust_fun: fn(arg: i32) -> u32, + example_c_fun: unsafe extern "C" fn(), + example_reference: &'a mut i32, +} + +fn main(){ + let mut cont: Container = + unsafe { Container::load("libexample.so") }.expect("Could not open library or load symbols"); + cont.example_rust_fun(5); + unsafe{cont.example_c_fun()}; + *cont.example_reference_mut() = 5; +} +``` + # Features ## Main features @@ -36,6 +60,7 @@ I hope that this library will help you to quickly get what you need and avoid er | Low-level, unsafe API | Yes | Yes | Yes | | Object-oriented friendly | Yes | **No** | Yes | | Load from the program itself | Yes | **No** | **No** | +| Obtaining address information (dladdr) | Yes | **Unix only** | **no**| ## Safety