Files
aho_corasick
ansi_term
array_tool
atty
bitflags
cargo_update
cfg_if
clap
dirs
dirs_sys
form_urlencoded
git2
hex
idna
json
lazy_static
lazysort
libc
libgit2_sys
libssh2_sys
libz_sys
log
matches
maybe_uninit
memchr
openssl_probe
openssl_sys
percent_encoding
proc_macro2
quote
regex
regex_syntax
semver
semver_parser
serde
serde_derive
smallvec
strsim
syn
tabwriter
term_size
textwrap
toml
unicode_bidi
unicode_normalization
unicode_width
unicode_xid
url
vec_map
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Bindings to libgit2's raw `git_oidarray` type

use std::ops::Deref;

use crate::oid::Oid;
use crate::raw;
use crate::util::Binding;
use std::mem;
use std::slice;

/// An oid array structure used by libgit2
///
/// Some apis return arrays of oids which originate from libgit2. This
/// wrapper type behaves a little like `Vec<&Oid>` but does so without copying
/// the underlying Oids until necessary.
pub struct OidArray {
    raw: raw::git_oidarray,
}

impl Deref for OidArray {
    type Target = [Oid];

    fn deref(&self) -> &[Oid] {
        unsafe {
            debug_assert_eq!(mem::size_of::<Oid>(), mem::size_of_val(&*self.raw.ids));

            slice::from_raw_parts(self.raw.ids as *const Oid, self.raw.count as usize)
        }
    }
}

impl Binding for OidArray {
    type Raw = raw::git_oidarray;
    unsafe fn from_raw(raw: raw::git_oidarray) -> OidArray {
        OidArray { raw: raw }
    }
    fn raw(&self) -> raw::git_oidarray {
        self.raw
    }
}

impl<'repo> std::fmt::Debug for OidArray {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
        f.debug_tuple("OidArray").field(&self.deref()).finish()
    }
}

impl Drop for OidArray {
    fn drop(&mut self) {
        unsafe { raw::git_oidarray_free(&mut self.raw) }
    }
}