summaryrefslogtreecommitdiffstats
path: root/src/property.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/property.rs')
-rw-r--r--src/property.rs70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/property.rs b/src/property.rs
index 133f953..55b5914 100644
--- a/src/property.rs
+++ b/src/property.rs
@@ -6,55 +6,57 @@ use super::component::IcalComponent;
use crate::ical;
pub struct IcalProperty<'a> {
- pub ptr: *mut ical::icalproperty,
- _parent: &'a dyn IcalComponent,
+ pub ptr: *mut ical::icalproperty,
+ _parent: &'a dyn IcalComponent,
}
impl<'a> Drop for IcalProperty<'a> {
- fn drop(&mut self) {
- unsafe {
- ical::icalproperty_free(self.ptr);
+ fn drop(&mut self) {
+ unsafe {
+ ical::icalproperty_free(self.ptr);
+ }
}
- }
}
impl<'a> fmt::Debug for IcalProperty<'a> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.as_ical_string())
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{}", self.as_ical_string())
+ }
}
impl<'a> IcalProperty<'a> {
- pub fn from_ptr(ptr: *mut ical::icalproperty, parent: &'a dyn IcalComponent) -> Self {
- IcalProperty { ptr, _parent: parent }
- }
-
- pub fn get_name(&self) -> String {
- unsafe {
- let cstr = CStr::from_ptr(ical::icalproperty_get_property_name(self.ptr));
- cstr.to_string_lossy().into_owned()
+ pub fn from_ptr(ptr: *mut ical::icalproperty, parent: &'a dyn IcalComponent) -> Self {
+ IcalProperty {
+ ptr,
+ _parent: parent,
+ }
}
- }
- pub fn get_value(&self) -> String {
- unsafe {
- let cstr = CStr::from_ptr(ical::icalproperty_get_value_as_string(self.ptr));
- cstr.to_string_lossy().into_owned()
+ pub fn get_name(&self) -> String {
+ unsafe {
+ let cstr = CStr::from_ptr(ical::icalproperty_get_property_name(self.ptr));
+ cstr.to_string_lossy().into_owned()
+ }
}
- }
- pub fn as_ical_string(&self) -> String {
- unsafe {
- let cstr = CStr::from_ptr(ical::icalproperty_as_ical_string(self.ptr));
- cstr.to_string_lossy().trim().to_owned()
+ pub fn get_value(&self) -> String {
+ unsafe {
+ let cstr = CStr::from_ptr(ical::icalproperty_get_value_as_string(self.ptr));
+ cstr.to_string_lossy().into_owned()
+ }
}
- }
- pub fn get_value_as_date(&self) -> Option<NaiveDate> {
- unsafe {
- let date = ical::icaltime_from_string(ical::icalproperty_get_value_as_string(self.ptr));
- NaiveDate::from_ymd_opt(date.year, date.month as u32, date.day as u32)
+ pub fn as_ical_string(&self) -> String {
+ unsafe {
+ let cstr = CStr::from_ptr(ical::icalproperty_as_ical_string(self.ptr));
+ cstr.to_string_lossy().trim().to_owned()
+ }
}
- }
-}
+ pub fn get_value_as_date(&self) -> Option<NaiveDate> {
+ unsafe {
+ let date = ical::icaltime_from_string(ical::icalproperty_get_value_as_string(self.ptr));
+ NaiveDate::from_ymd_opt(date.year, date.month as u32, date.day as u32)
+ }
+ }
+}