Document ObjectName
This commit is contained in:
parent
2892430fa7
commit
91dc916615
|
|
@ -15,6 +15,8 @@ fn hash_object_name(v: &glib::Variant) -> u32 {
|
||||||
unsafe { ostree_sys::ostree_hash_object_name(v.to_glib_none().0 as glib_sys::gconstpointer) }
|
unsafe { ostree_sys::ostree_hash_object_name(v.to_glib_none().0 as glib_sys::gconstpointer) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A reference to an object in an OSTree repo. It contains both a checksum and an
|
||||||
|
/// [ObjectType](enum.ObjectType.html) which together identify an object in a repository.
|
||||||
#[derive(Eq, Debug)]
|
#[derive(Eq, Debug)]
|
||||||
pub struct ObjectName {
|
pub struct ObjectName {
|
||||||
variant: glib::Variant,
|
variant: glib::Variant,
|
||||||
|
|
@ -23,6 +25,7 @@ pub struct ObjectName {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectName {
|
impl ObjectName {
|
||||||
|
/// Create a new `ObjectName` from a serialized representation.
|
||||||
pub fn new_from_variant(variant: glib::Variant) -> ObjectName {
|
pub fn new_from_variant(variant: glib::Variant) -> ObjectName {
|
||||||
let deserialize = object_name_deserialize(&variant);
|
let deserialize = object_name_deserialize(&variant);
|
||||||
ObjectName {
|
ObjectName {
|
||||||
|
|
@ -32,9 +35,11 @@ impl ObjectName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new `ObjectName` with the given checksum and `ObjectType`.
|
||||||
pub fn new<S: Into<GString>>(checksum: S, object_type: ObjectType) -> ObjectName {
|
pub fn new<S: Into<GString>>(checksum: S, object_type: ObjectType) -> ObjectName {
|
||||||
let checksum = checksum.into();
|
let checksum = checksum.into();
|
||||||
let variant = object_name_serialize(checksum.as_str(), object_type).unwrap();
|
let variant = object_name_serialize(checksum.as_str(), object_type)
|
||||||
|
.expect("type checks should make this safe");
|
||||||
ObjectName {
|
ObjectName {
|
||||||
variant,
|
variant,
|
||||||
checksum,
|
checksum,
|
||||||
|
|
@ -42,15 +47,18 @@ impl ObjectName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a reference to this `ObjectName`'s checksum string.
|
||||||
pub fn checksum(&self) -> &str {
|
pub fn checksum(&self) -> &str {
|
||||||
self.checksum.as_str()
|
self.checksum.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return this `ObjectName`'s `ObjectType`.
|
||||||
pub fn object_type(&self) -> ObjectType {
|
pub fn object_type(&self) -> ObjectType {
|
||||||
self.object_type
|
self.object_type
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> GString {
|
/// Format this `ObjectName` as a string.
|
||||||
|
fn to_string(&self) -> GString {
|
||||||
object_to_string(self.checksum(), self.object_type())
|
object_to_string(self.checksum(), self.object_type())
|
||||||
.expect("type checks should make this safe")
|
.expect("type checks should make this safe")
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +66,7 @@ impl ObjectName {
|
||||||
|
|
||||||
impl Display for ObjectName {
|
impl Display for ObjectName {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||||
write!(f, "{}", self.name())
|
write!(f, "{}", self.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue