From afccf012168dcab1de89f3737014ee8ee037785b Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Wed, 11 May 2022 17:20:08 +0200 Subject: [PATCH] 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. --- src/entry.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/entry.rs b/src/entry.rs index fb4fa4a..d2c7769 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -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) { + self.ty = Some(ty.into()); + } + /// Creates a new Property (key/value) KdlEntry. pub fn new_prop(key: impl Into, value: impl Into) -> Self { KdlEntry {