Skip to main content

libghostty_vt_sys/
lib.rs

1#![allow(non_camel_case_types)]
2#![allow(non_snake_case)]
3#![allow(non_upper_case_globals)]
4#![allow(clippy::all)]
5#![allow(rustdoc::all)]
6
7mod bindings;
8
9use std::ops::Deref;
10
11pub use bindings::*;
12
13/// Initialize a "sized" FFI object.
14#[macro_export]
15macro_rules! sized {
16    ($ty:ty) => {{
17        let mut t = <$ty as ::std::default::Default>::default();
18        t.size = ::std::mem::size_of::<$ty>();
19        t
20    }};
21}
22
23impl<S> From<S> for bindings::String
24where
25    S: Deref<Target = str>,
26{
27    fn from(value: S) -> Self {
28        Self {
29            ptr: value.as_ptr(),
30            len: value.len(),
31        }
32    }
33}
34
35impl bindings::String {
36    /// # Safety
37    ///
38    /// The caller must uphold that the associated lifetime is valid
39    /// with the given context behind the FFI string, and that it contains
40    /// valid UTF-8 data.
41    pub unsafe fn to_str<'a>(self) -> &'a str {
42        // SAFETY: To be upheld by caller
43        let slice = unsafe { std::slice::from_raw_parts(self.ptr, self.len) };
44        unsafe { std::str::from_utf8_unchecked(slice) }
45    }
46}