gccjit 6.1.0

Higher-level Rust bindings for libgccjit.
Documentation
use context::Context;
use object;
use object::{Object, ToObject};
use std::fmt;
use std::marker::PhantomData;

use crate::with_lib_without_error_check;

/// A Location represents a location used when debugging jitted code.
#[derive(Copy, Clone)]
pub struct Location<'ctx> {
    marker: PhantomData<&'ctx Context<'ctx>>,
    ptr: *mut gccjit_sys::gcc_jit_location,
}

impl<'ctx> ToObject<'ctx> for Location<'ctx> {
    fn to_object(&self) -> Object<'ctx> {
        with_lib_without_error_check(|lib| unsafe {
            object::from_ptr(lib.gcc_jit_location_as_object(get_ptr(self)))
                .expect("Failed to get Object from Location")
        })
    }
}

impl<'ctx> crate::ContextGetter<'ctx> for Location<'ctx> {
    fn context(&self) -> crate::ContextRef<'ctx> {
        self.to_object().context()
    }
}

impl<'ctx> fmt::Debug for Location<'ctx> {
    fn fmt<'a>(&self, fmt: &mut fmt::Formatter<'a>) -> Result<(), fmt::Error> {
        let obj = self.to_object();
        obj.fmt(fmt)
    }
}

impl<'ctx> Location<'ctx> {
    pub fn null() -> Self {
        Location {
            marker: std::marker::PhantomData,
            ptr: core::ptr::null_mut(),
        }
    }
}

pub unsafe fn from_ptr<'ctx>(ptr: *mut gccjit_sys::gcc_jit_location) -> Location<'ctx> {
    Location {
        marker: PhantomData,
        ptr,
    }
}

pub unsafe fn get_ptr<'ctx>(loc: &Location<'ctx>) -> *mut gccjit_sys::gcc_jit_location {
    loc.ptr
}