pub struct ObjectIdPrefix { /* private fields */ }Expand description
Four through the full hash width hexadecimal digits in one object format.
Parsing normalizes uppercase digits and preserves odd widths. It does not establish existence
or uniqueness; use crate::Objects::resolve_prefix for that.
Implementations§
Source§impl ObjectIdPrefix
impl ObjectIdPrefix
Sourcepub fn from_hex(
format: ObjectFormat,
text: &str,
) -> Result<Self, ParseObjectIdPrefixError>
pub fn from_hex( format: ObjectFormat, text: &str, ) -> Result<Self, ParseObjectIdPrefixError>
Parses ASCII hexadecimal digits for the selected repository format.
§Errors
Rejects fewer than four digits, more than the full width, or non-hexadecimal input.
use girt::{ObjectFormat, ObjectIdPrefix};
let prefix = ObjectIdPrefix::from_hex(ObjectFormat::Sha1, "B6FC4")?;
assert_eq!(prefix.to_string(), "b6fc4");Examples found in repository?
examples/short_ids.rs (line 13)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let mut args = std::env::args().skip(1);
5 let path = args
6 .next()
7 .ok_or("usage: short_ids <repository> <hex-prefix>")?;
8 let text = args.next().ok_or("missing hexadecimal prefix")?;
9
10 let repository = Repository::discover(path)?;
11 let objects = repository.objects()?;
12
13 let prefix = ObjectIdPrefix::from_hex(repository.object_format(), &text)?;
14 let id = objects.resolve_prefix(prefix)?;
15 println!("{}", objects.abbreviate(id, objects.auto_abbrev_len())?);
16 Ok(())
17}Sourcepub fn object_format(self) -> ObjectFormat
pub fn object_format(self) -> ObjectFormat
The selected hash format.
Trait Implementations§
Source§impl Clone for ObjectIdPrefix
impl Clone for ObjectIdPrefix
impl Copy for ObjectIdPrefix
Source§impl Debug for ObjectIdPrefix
impl Debug for ObjectIdPrefix
Source§impl Display for ObjectIdPrefix
impl Display for ObjectIdPrefix
impl Eq for ObjectIdPrefix
Source§impl Hash for ObjectIdPrefix
impl Hash for ObjectIdPrefix
Source§impl PartialEq for ObjectIdPrefix
impl PartialEq for ObjectIdPrefix
impl StructuralPartialEq for ObjectIdPrefix
Auto Trait Implementations§
impl Freeze for ObjectIdPrefix
impl RefUnwindSafe for ObjectIdPrefix
impl Send for ObjectIdPrefix
impl Sync for ObjectIdPrefix
impl Unpin for ObjectIdPrefix
impl UnsafeUnpin for ObjectIdPrefix
impl UnwindSafe for ObjectIdPrefix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more