Debian Codegraph @

src/push_update.rs

raw
1 use crate::util::Binding;
2 use crate::{raw, Error, Oid};
3 use std::marker;
4 use std::str;
5
6 /// Represents an update which will be performed on the remote during push.
7 pub struct PushUpdate<'a> {
8 raw: *const raw::git_push_update,
9 _marker: marker::PhantomData<&'a raw::git_push_update>,
10 }
11
12 impl<'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
25 impl 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.
32 pub fn src_refname(&self) -> Result<&str, Error> {
33 str::from_utf8(self.src_refname_bytes()).map_err(|e| e.into())
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.
42 pub fn dst_refname(&self) -> Result<&str, Error> {
43 str::from_utf8(self.dst_refname_bytes()).map_err(|e| e.into())
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 }