Re: [PATCH v4 4/5] libgit: add higher-level libgit crate
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Oct 9, 2024, 06:18 UTC
- Message-ID
- <CAPig+cQEE=rOxb49rHHY5sDvSFm4+nU6RdFgXmQyt8EhMpFMLg@mail.gmail.com>
- In-Reply-To
- <29599e9c7be1737bcf0de0541c9635212a1b691d.1728429158.git.steadmon@google.com>
On Tue, Oct 8, 2024 at 7:19 PM Josh Steadmon <steadmon@google.com> wrote:
Show 21 quoted lines
> Wrap `struct config_set` and a few of its associated functions in
> libgit-sys. Also introduce a higher-level "libgit" crate which provides
> a more Rust-friendly interface to config_set structs.
>
> Signed-off-by: Calvin Wan <calvinwan@google.com>
> Signed-off-by: Josh Steadmon <steadmon@google.com>
> ---
> diff --git a/contrib/libgit-rs/src/lib.rs b/contrib/libgit-rs/src/lib.rs
> @@ -0,0 +1,95 @@
> +pub struct ConfigSet(*mut libgit_config_set);
> +impl ConfigSet {
> + pub fn get_int(&mut self, key: &str) -> Option<c_int> {
> + let key = CString::new(key).expect("Couldn't convert to CString");
> + let mut val: c_int = 0;
> + unsafe {
> + if libgit_configset_get_int(self.0, key.as_ptr(), &mut val as *mut c_int) != 0 {
> + return None;
> + }
> + }
> + Some(val)
> + }Considering that v4 finally gets around to swapping out `CString` for `String` in order to make this high-level crate more Rust-programmer-friendly, I was more than a little surprised to see that this function is still exposing `c_int` rather than, say, `i64` or such.