git2/
push_update.rs

1use crate::util::Binding;
2use crate::{raw, Oid};
3use std::marker;
4use std::str;
5
6/// Represents an update which will be performed on the remote during push.
7pub struct PushUpdate<'a> {
8    raw: *const raw::git_push_update,
9    _marker: marker::PhantomData<&'a raw::git_push_update>,
10}
11
12impl<'a> Binding for PushUpdate<'a> {
13    type Raw = *const raw::git_push_update;
14    unsafe fn from_raw(raw: *const raw::git_push_update) -> PushUpdate<'a> {
15        PushUpdate {
16            raw,
17            _marker: marker::PhantomData,
18        }
19    }
20    fn raw(&self) -> Self::Raw {
21        self.raw
22    }
23}
24
25impl PushUpdate<'_> {
26    /// Returns the source name of the reference as a byte slice.
27    pub fn src_refname_bytes(&self) -> &[u8] {
28        unsafe { crate::opt_bytes(self, (*self.raw).src_refname).unwrap() }
29    }
30
31    /// Returns the source name of the reference, or None if it is not valid UTF-8.
32    pub fn src_refname(&self) -> Option<&str> {
33        str::from_utf8(self.src_refname_bytes()).ok()
34    }
35
36    /// Returns the name of the reference to update on the server as a byte slice.
37    pub fn dst_refname_bytes(&self) -> &[u8] {
38        unsafe { crate::opt_bytes(self, (*self.raw).dst_refname).unwrap() }
39    }
40
41    /// Returns the name of the reference to update on the server, or None if it is not valid UTF-8.
42    pub fn dst_refname(&self) -> Option<&str> {
43        str::from_utf8(self.dst_refname_bytes()).ok()
44    }
45
46    /// Returns the current target of the reference.
47    pub fn src(&self) -> Oid {
48        unsafe { Binding::from_raw(&(*self.raw).src as *const _) }
49    }
50
51    /// Returns the new target for the reference.
52    pub fn dst(&self) -> Oid {
53        unsafe { Binding::from_raw(&(*self.raw).dst as *const _) }
54    }
55}