Skip to content

Instantly share code, notes, and snippets.

@Alxandr
Last active December 15, 2020 19:02
Show Gist options
  • Save Alxandr/70a4e3507f309b5006c0ef6da6c1a5e6 to your computer and use it in GitHub Desktop.
Save Alxandr/70a4e3507f309b5006c0ef6da6c1a5e6 to your computer and use it in GitHub Desktop.
use crate::tag::TagLookup;
use git2::Repository;
pub struct Context {
// NOTE: This lifetime is fake
tags: TagLookup<'static>,
// IMPORTANT: this has to be last to be dropped last
repo: Box<Repository>,
}
impl Context {
fn create(repo: Repository) -> Result<Context, git2::Error> {
let repo = Box::new(repo);
let tags: TagLookup<'static> = {
let repo = &*repo;
let lookup = TagLookup::create(&repo, None)?;
unsafe { std::intrinsics::transmute(lookup) }
};
let context = unsafe { Context { repo, tags } };
Ok(context)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment