Skip to main content

gix_object/tag/
mod.rs

1use crate::parse::parse_signature;
2use crate::TagRef;
3
4mod decode;
5
6///
7pub mod write;
8
9///
10pub mod ref_iter;
11
12impl<'a> TagRef<'a> {
13    /// Deserialize a tag from `data`.
14    pub fn from_bytes(mut data: &'a [u8], hash_kind: gix_hash::Kind) -> Result<TagRef<'a>, crate::decode::Error> {
15        let input = &mut data;
16        match decode::git_tag(input, hash_kind) {
17            Ok(tag) => Ok(tag),
18            Err(err) => Err(err),
19        }
20    }
21    /// The object this tag points to as `Id`.
22    pub fn target(&self) -> gix_hash::ObjectId {
23        gix_hash::ObjectId::from_hex(self.target).expect("prior validation")
24    }
25
26    /// Return the tagger, if present.
27    pub fn tagger(&self) -> Result<Option<gix_actor::SignatureRef<'a>>, crate::decode::Error> {
28        Ok(self
29            .tagger
30            .map(parse_signature)
31            .transpose()?
32            .map(|signature| signature.trim()))
33    }
34
35    /// Copy all data into a fully-owned instance.
36    pub fn into_owned(self) -> Result<crate::Tag, crate::decode::Error> {
37        self.try_into()
38    }
39}