pub struct Oid { /* private fields */ }Expand description
Unique identity of any object (commit, tree, blob, tag).
Implementations§
Source§impl Oid
impl Oid
Sourcepub fn from_str(s: &str) -> Result<Oid, Error>
pub fn from_str(s: &str) -> Result<Oid, Error>
Parse a hex-formatted object id into an Oid structure.
This always parses as SHA1 (up to 40 hex characters). Use
Oid::from_str_ext to parse with a specific format.
§Errors
Returns an error if the string is empty, is longer than 40 hex characters, or contains any non-hex characters.
Sourcepub fn from_str_ext(s: &str, format: ObjectFormat) -> Result<Oid, Error>
pub fn from_str_ext(s: &str, format: ObjectFormat) -> Result<Oid, Error>
Parses a hex-formatted object id with a specific object format.
§Errors
Returns an error if the string is
- is empty
- is longer than 40 hex with SHA1 object format
- is longer than 64 hex with SHA256 object format
- contains any non-hex characters
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Oid, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Oid, Error>
Parse a raw object id into an Oid structure.
If the array given is not 20 bytes in length, an error is returned.
Sourcepub fn zero() -> Oid
👎Deprecated since 0.21.0: use Oid::ZERO_SHA1 instead
pub fn zero() -> Oid
use Oid::ZERO_SHA1 instead
Creates an all-zero SHA1 OID.
Sourcepub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result<Oid, Error>
pub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result<Oid, Error>
Hashes the provided data as an object of the provided type, and returns an Oid corresponding to the result. This does not store the object inside any object database or repository.
This always hashes using SHA1. Use Oid::hash_object_ext
to hash with a specific format.
Sourcepub fn hash_object_ext(
kind: ObjectType,
bytes: &[u8],
format: ObjectFormat,
) -> Result<Oid, Error>
pub fn hash_object_ext( kind: ObjectType, bytes: &[u8], format: ObjectFormat, ) -> Result<Oid, Error>
Hashes the provided data as an object of the provided type, with a specific object format.
See Oid::hash_object for more details.
Sourcepub fn hash_file<P: AsRef<Path>>(
kind: ObjectType,
path: P,
) -> Result<Oid, Error>
pub fn hash_file<P: AsRef<Path>>( kind: ObjectType, path: P, ) -> Result<Oid, Error>
Hashes the content of the provided file as an object of the provided type, and returns an Oid corresponding to the result. This does not store the object inside any object database or repository.
This always hashes using SHA1. Use Oid::hash_file_ext
to hash with a specific format.
Sourcepub fn hash_file_ext<P: AsRef<Path>>(
kind: ObjectType,
path: P,
format: ObjectFormat,
) -> Result<Oid, Error>
pub fn hash_file_ext<P: AsRef<Path>>( kind: ObjectType, path: P, format: ObjectFormat, ) -> Result<Oid, Error>
Hashes the content of a file as an object of the provided type, with a specific object format.
See Oid::hash_file for more details.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
View this OID as a byte-slice in its logical length: 20 bytes for SHA1, 32 bytes for SHA256.
Sourcepub fn object_format(&self) -> ObjectFormat
pub fn object_format(&self) -> ObjectFormat
Returns the ObjectFormat of this OID.
Without the unstable-sha256 feature, this always returns
ObjectFormat::Sha1.