mirror of https://github.com/kdl-org/kdl-rs.git
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:
parent
ac3ca5773f
commit
afccf01216
15
src/entry.rs
15
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<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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue