Skip to content

OwnedSymbol #104

@constvoidptr

Description

@constvoidptr

I needed the ability the cache multiple Symbols in a struct across FFI calls.

I didn't want to use a self referental struct, so instead I created a OwnedSymbol type that keeps
the library alive as long as needed.

pub struct OwnedSymbol<T> {
    inner: imp::Symbol<T>,
    library: Arc<Library>,
}

// Obtain a OwnedSymbol
impl Library {
  pub unsafe fn get_owned<T>(self: Arc<Self>, symbol: &[u8]) -> Result<OwnedSymbol<T>, Error> {
      self.0
          .get(symbol)
          .map(|from| OwnedSymbol::from_raw(from, self))
  }
}

https://github.com/constvoidptr/rust_libloading/blob/768dc11b4fa3d48527a6406d56e3100c7f49a376/src/safe.rs#L308

Is that something you'd like to see upstream? I've seen a few issues/pr's that reference something similar.
If so, I would document the new type and functions, write the tests and get a pull request going.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions