hummingly / ics Goto Github PK
View Code? Open in Web Editor NEWA Rust library for creating iCalendar files as specified in RFC5545 and RFC7986
License: Other
A Rust library for creating iCalendar files as specified in RFC5545 and RFC7986
License: Other
escape_text
Property
Parameter
Value
typeFromStr
implementation for types, properties and parametersIn some cases there is only a range of values for some properties and parameters. Those could be converted to enums
:
pub fn new(action: Action, trigger: Trigger) -> Self
constructor.I just realized that the crate cannot be build with default features off.
property_builder!
macro.While each property has a type, not all values make sense or are allowed.
Into<Cow<str>>
for Parameter enumsjoin!
& join_text
macro
join_test!
would use the escape_test
function for each value.join!(("Formatter")*, (method on each value)*, &[T: impl Display])
list
method instead of join (for parameters)#[feature = "rfc7986"]
#7 #8It would be very cool if you could do
use ics::{Event, properties::*};
use chrono::prelude::*;
let start = Utc::now();
let end = start + Duration::hours(1);
let mut event = Event::new("Some test event", start);
event.push(DtStart::new(start));
event.push(DtEnd::new(end));
I can understand it if you don't always want to include the chrono
dependency for this, but a non-default feature would also be nice.
Since ical's date format does not seem very standard, it doesn't have a conversion function built-in in chrono
, meaning you have to do the following yourself:
fn dt_to_ical(dt: DateTime<Utc>) -> String {
// .format is lazy, so you have to wrap it again inside `format!` to get an actual String
format!("{}", dt.format("%Y%m%dT%H%M%SZ"))
}
// ...
event.push(DtStart::new(dt_to_ical(start)); // etc
Given that chrono
is a pretty popular crate for datetimes, this does not feel very smooth.
FBTime -> FreeBusyTime
parameters::TZID -> TzID (test if it conflicts with other TzID)
Some properties can take a list of values which is why the library should offer a simple Iterator based List type.
The conversion is a bit misleading as it only converts it into the value of the parameter. Futhermore, the builder types do not implement this trait! Most importantly this "leaks" implementation details.
pub fn into(self) -> Cow<str>
-> fn as_value(self) -> Cow<str>
I'd love to see the possibility to not only create but also parse ical files.
We can avoid one loop in fold_line
by not clearing the whole String but just after the first 75 bytes and collect the Drain iterator into the read only slice.
/// Inside fold_line
// Getting the length before mutating the content removes the possibility of bugs
let len = content_line.len();
// drain the first 75 bytes or before if the boundary is not on a char boundary
let mut boundary = LINE_LIMIT;
// looks for the end of a UTF-8 code point
while !input.is_char_boundary(boundary) {
boundary -= 1;
}
let input: String = content_line.drain(boundary..).collect();
// if it works it should remove the need for having to borrow input before slicing it
let input = input.as_str();
// we do not need to check if the boundary is smaller than len since fold_line is called only when the content is longer than LINE_LIMIT
content_line.push_str("\r\n ");
Furthermore, we can allocate more precisely the capacity of the output String in the escape_value_regex
by doing the same as in escape_value
. This is still not 100% accurate but better than allocating half when there is only one comma.
/// Inside escape_value_regex
let size = input.len() + input.chars().filter(|&c| escaped_char(c)).count();
let mut output = String::with_capacity(size);
escaped_char
becomes escaped_chars
and maybe a closure in at least escape_value_regex
.
nevermind, invalid
This will add editing methods which makes the components in the library useful for parsing. The library itself doesn't offer parsing but this way one can implement it.
FromStr
?pub fn contains(&self, property: &str) -> bool
pub fn get(&self, property: &str) -> Option<Vec<&Property>>
pub fn properties(&self) -> Option<Vec<&Property>>
pub fn components<C: Into<Component>(&self) -> Option<Vec<&C>>
pub fn name(&self) -> &str
pub fn value(&self) -> &str
pub fn parameters(&self) -> Option<&Parameters>
pub fn get_mut(&mut self, property: &str) -> Option<&mut Vec<Property>>
pub fn replace(&mut self, property: &str, index: usize, replacement_val: &str) -> Option<Property>
pub fn replace_first(&mut self, property: &str, replacement_val: &str) -> Option<Property>
pub fn replace_all(&mut self, property: &str, replacement: &[Property]) -> Option<&[Property]>
pub fn clear(&mut self)
pub fn remove_all(&mut self, property: &str) -> Option<Vec<&Property>>
Hello, there.
I have a issue with next_boundary function.
Could you please fix this issue?
For exmaple, change 71 line in contentline.rs
let content = "Content lines shouldn't be folded in the middle of a UTF-8 character! 老虎.";
to
let content = "Content lines shouldn't be folded in the middle of a UTF-8 character! 老 虎.";
and cargo test
---- contentline::tests::multibytes stdout ----
thread 'contentline::tests::multibytes' panicked at 'byte index 76 is not a char boundary; it is inside '虎' (bytes 74..77) of `Content lines shouldn't be folded in the middle of a UTF-8 character! 老 虎.`', src/contentline.rs:30:11
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.