Closed ModProg closed 2 years ago
This is based on #24. This is a more fundamental refactor, that really only makes sense in the picture of parsing and implementing getters for standard properties.
Haven't read the code yet, but does this mean that you can't have duplicate keys?
Haven't read the code yet, but does this mean that you can't have duplicate keys?
you can, either by calling Component::property_appended
twice or using Component::multi_property
parsing something like ["A", "B"]
.
But if all of these changes make sense depends on your future plans so this probably cannot be pushed as is :smile:
I'm reading through the changes and I have to admit I have a bunch of questions. Can you tell me a bit about your motivation here and why you'd like to make these refactorings. Because it seems a bit to me like we're not talking about the same things.
Maybe I can start with where I'm coming from:
I was going to merge that parser branch at some point and I was thinking to make the underlying data structures look more similar to that of the parser's output (more tree, less hashmap style).
So a calendar would be a Vec<Component>
and a component would have a Vec<Property>
etc.
Now that is very different from what you are building here, but my data structure also has a bunch of downsides.
So I'm currently thinking:
a: does this library now need two separateCalendar
types, one for parsing/serializing and one for the builder-pattern.
or b: is all you need different methods for the builder pattern? because then the underlying datastructure is not all that important.
I have to admit also: I don't really like the method names that you picked in this PR, they seem less descriptive than what's already there. This is why I'm having a hard time understanding what you want from this.
Maybe I was a little over ambitious with this, I see where your confusion comes from, I also had a hard time thinking about what to name what.
So these are the things that I think could be nice, and I tried building with this.
Into<Property>
to allow for a single method for setting both simple values by passing a string, and more complex values by passing the Property
struct.Map<Key, Property>
. This could also be realized by having a get_property
method that just searches/filters Vec<Property
. (This is not really implemented by this, but would be the next step for my approach.)a: does this library now need two separateCalendar types, one for parsing/serializing and one for the builder-pattern.
I hope not, I would like to have a datatype, that would just be built by the parser, and then can be used with the builder + getter functions (which don't exist yet) and then can be serialized back to the String.
I have to admit also: I don't really like the method names that you picked in this PR, they seem less descriptive than what's already there. This is why I'm having a hard time understanding what you want from this.
That's alright, I am definitely not the best at naming stuff, and we can use better names.
summary
, start
, location
etc.This could be implemented for all possible data Structures really:
Map<Key, Vec<Property>>
Map<Key, Property> + Vec<Property>
Vec<Property>
clear_property() -> Self
get_property(key:String) -> Option<Property>
or referenceget_properties(key:String) -> Vec<Property>
or sliceappend_property(key:String, Into<Property>) -> Self
replace_property(key:String, Into<Property>) -> Self
(is really just clear
+ append
)start(DateTime) -> Self
get_start() -> Option<DateTime>
remove_start() -> Self
These should maybe also have an append.
I just finished this pending review, sorry if some comments are a bit out of date, I wrote this before writing my comment
I just finished this pending review, sorry if some comments are a bit out of date, I wrote this before writing my comment
That's alright, Sorry to just dump so much code on you. I should have better explained my ideas beforehand.
Hopefully my comment https://github.com/hoodie/icalendar-rs/pull/25#issuecomment-954890582 especially the lower half explains what I want to achieve, and maybe you have a better idea for data handling and api naming than me :laughing:
Sorry to just dump so much code on you. I should have better explained my ideas beforehand.
It's ok, I like if people chime in on stuff. I'll take it into consideration, but I think I'll give the parser work preferential treatment for now and then see how we can incorporate both things.
It's ok, I like if people chime in on stuff. I'll take it into consideration, but I think I'll give the parser work preferential treatment for now and then see how we can incorporate both things.
That's fair, like I said, in the end the internal data structure is not that relevant for me and I would be fine with just implementing the methods outlined above on what ever data structure you settle on.
feat: new way of storing/setting properties
All properties can now be set using
Component::property
andComponent::multi_property
to overwrite an existing value andComponent::property_appended
andComponent::multi_property_appended
to append to the existing value. This is achieved through implementingFrom<ToString> for Property
With this changeComponent::with_property_set
andComponent::with_property_appended
are only for internal use.All properties are now stored in a single
Map<String, Vec<Property>>
(both multi properties and single value properties). The key is now only stored through the map and no longer duplicated in theProperty
thereforComponent::with_property_set
andComponent::with_property_appended
take the tuple(Key, Value)
now. The same is true for parameters.For consistency
Calendar
behaves the same way only thatCalendar::property
always appends, because Calendar still uses a Vec to store properties.BREAKING CHANGE: setting properties and parameters changed for Calendar and Components