`main` function not found in crate with #![cfg(feature = "chrono-tz")]

Breaking into Rust, have a simple use case of taking csv data and create a iCal event list from it.
example from the icalendar library can be found here: icalendar-rs/examples/timezone.rs at main · hoodie/icalendar-rs · GitHub

simply copying that into my main.rs and I get:
main function not found in crate

but if I take out the cfg line I get:
"no variant or associated item named from_ymd_hm_tzid found for enum icalendar::CalendarDateTime"

Cargo.toml

[package]
name = "bgl-cal"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at The Manifest Format - The Cargo Book

[dependencies]
chrono = "0.4.33"
chrono-tz = "0.8.5"
icalendar = "0.16.0"

pretty lost on simple setup I think.
Any advice on what could be going on with my setup?
Thanks

[package]
name = "bgl-cal"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at The Manifest Format - The Cargo Book

[dependencies]
chrono = "0.4.33"
chrono-tz = "0.8.5"
- icalendar = "0.16.0"
+ icalendar = { version = "0.16", features = ["chrono-tz"] }

should do the trick I think.

Thank you! Do you have some reading you can recommend so I can know more about this?

1 Like

Sure, what you have here are Cargo's features. They are a mechanism to minimize the functionality of a library to a set that you need, rather than you having all the functionality and using only a subset of it. This speeds up compilation and may be used to reduce the overhead of your dependency tree. In your case, people might not need the chrono-tz integration, so the icalendar devs decided to put it behind the chrono-tz feature gate. If you don't enable the feature, you don't get the CalendarDateTime::from_ymd_hm_tzid function, because it is behind a #[cfg(feature = "chrono-tz")], meaning the function won't be compiled if the feature is disabled.

1 Like

Great thank you!

1 Like