24 lines
6.9 KiB
HTML
24 lines
6.9 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Bindings around the platform’s dynamic library loading primitives with greatly improved memory safety."><title>libloading - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="libloading" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../libloading/index.html">libloading</a><span class="version">0.8.5</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#installation" title="Installation">Installation</a></li><li><a href="#usage" title="Usage">Usage</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>libloading</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/libloading/lib.rs.html#1-78">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Bindings around the platform’s dynamic library loading primitives with greatly improved memory safety.</p>
|
||
<p>Using this library allows the loading of <a href="struct.Library.html">dynamic libraries</a>, also known as
|
||
shared libraries, and the use of the functions and static variables they contain.</p>
|
||
<p>The <code>libloading</code> crate exposes a cross-platform interface to load a library and make use of its
|
||
contents, but little is done to hide the differences in behaviour between platforms.
|
||
The API documentation strives to document such differences as much as possible.</p>
|
||
<p>Platform-specific APIs are also available in the <a href="os/index.html" title="mod libloading::os"><code>os</code></a> module. These APIs are more
|
||
flexible, but less safe.</p>
|
||
<h2 id="installation"><a class="doc-anchor" href="#installation">§</a>Installation</h2>
|
||
<p>Add the <code>libloading</code> library to your dependencies in <code>Cargo.toml</code>:</p>
|
||
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
|
||
libloading = "0.8"</code></pre></div><h2 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h2>
|
||
<p>In your code, run the following:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>call_dynamic() -> <span class="prelude-ty">Result</span><u32, Box<<span class="kw">dyn </span>std::error::Error>> {
|
||
<span class="kw">unsafe </span>{
|
||
<span class="kw">let </span>lib = libloading::Library::new(<span class="string">"/path/to/liblibrary.so"</span>)<span class="question-mark">?</span>;
|
||
<span class="kw">let </span>func: libloading::Symbol<<span class="kw">unsafe extern fn</span>() -> u32> = lib.get(<span class="string">b"my_func"</span>)<span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(func())
|
||
}
|
||
}</code></pre></div>
|
||
<p>The compiler will ensure that the loaded function will not outlive the <code>Library</code> from which it comes,
|
||
preventing the most common memory-safety issues.</p>
|
||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="changelog/index.html" title="mod libloading::changelog">changelog</a></div><div class="desc docblock-short">The change log.</div></li><li><div class="item-name"><a class="mod" href="os/index.html" title="mod libloading::os">os</a></div><div class="desc docblock-short">Unsafe but flexible platform-specific bindings to dynamic library loading facilities.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Library.html" title="struct libloading::Library">Library</a></div><div class="desc docblock-short">A loaded dynamic library.</div></li><li><div class="item-name"><a class="struct" href="struct.Symbol.html" title="struct libloading::Symbol">Symbol</a></div><div class="desc docblock-short">Symbol from a library.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Error.html" title="enum libloading::Error">Error</a></div><div class="desc docblock-short">Errors.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.library_filename.html" title="fn libloading::library_filename">library_<wbr>filename</a></div><div class="desc docblock-short">Converts a library name to a filename generally appropriate for use on the system.</div></li></ul></section></div></main></body></html> |