pointersized

Crates.iopointersized
lib.rspointersized
version0.1.0
created_at2025-10-01 11:39:49.929375+00
updated_at2025-10-01 11:39:49.929375+00
descriptionMarking of pointer-sized types
homepage
repositoryhttps://github.com/qbstack/dynlink
max_upload_size
id1862448
size9,377
Ivan Kutuzov (ikute)

documentation

README

dynlink

Cross-platform dynamic linking.

This library provides a platform-independent API that allows dynamic linking shared objects, and use the data and functions they contains.

Usage

With this library shared object functions can be used.

use std::error;

use dynlink::api::Handle;

// sum.c
//
// int sum_of(int a, int b) {
//    return a + b;
// }

fn main() -> Result<(), Box<dyn error::Error>> {
    unsafe {
        let handle = Handle::open("libsum.so")?;
        let sum_fn = handle.lookup::<extern "C" fn(i32, i32) -> i32>("sum_of")?;

        println!("{}", sum_fn.apply(|f| f(1, 1)));

        Ok(())
    }
}

Platform-specific APIs are also available in the platform module.

#![cfg(target_os = "linux")]

use std::error;

use dynlink::platform::{PlatformHandle, RTLD_LAZY, RTLD_LOCAL};

fn main() -> Result<(), Box<dyn error::Error>> {
    unsafe {
        let handle = PlatformHandle::openc(c"libsum.so", RTLD_LOCAL | RTLD_LAZY)?;
        let sum_fn = handle.lookupc::<extern "C" fn(i32, i32) -> i32>(c"sum_of")?;
        println!("{}", sum_fn.apply(|f| f(1, 1)));

        Ok(())
    }
}
Commit count: 0

cargo fmt