feat(entry): Add accessors to entry type. (#43)

While the type of entries was parsed, there was no way for the library
user to access it. This commit let the user access the `ty` field of the
`KdlEntry` struct. It mirrors the accessors on the `value` field.
This commit is contained in:
Nicola Papale 2022-05-11 17:20:08 +02:00 committed by GitHub
parent ac3ca5773f
commit afccf01216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -49,6 +49,21 @@ impl KdlEntry {
self.value = value.into();
}
/// Gets the entry's type.
pub fn ty(&self) -> Option<&KdlIdentifier> {
self.ty.as_ref()
}
/// Gets a mutable reference to this entry's type.
pub fn ty_mut(&mut self) -> Option<&mut KdlIdentifier> {
self.ty.as_mut()
}
/// Sets the entry's type.
pub fn set_ty(&mut self, ty: impl Into<KdlIdentifier>) {
self.ty = Some(ty.into());
}
/// Creates a new Property (key/value) KdlEntry.
pub fn new_prop(key: impl Into<KdlIdentifier>, value: impl Into<KdlValue>) -> Self {
KdlEntry {