pub struct Writer<W: Write> { /* private fields */ }Expand description
Writes an iCalendar or vCard file.
Folds all content lines to lines that are no longer than 75 bytes (not including line breaks). A CRLF line break is appended to each content line.
Writer will always output valid UTF-8 to the underlying Write.
§Performance
It can be excessively inefficient to work directly with something that implements Write. For
example, every call to write on std::net::TcpStream results in a system call. Wrapping
writer in a io::BufWriter may improve performance significantly.
§Example
The following example illustrates how to write a simple vCard file:
use ical_vcard::{Contentline, Identifier, Param, ParamValue, Value, Writer};
let contentlines = [
Contentline::try_new("BEGIN", "VCARD")?,
Contentline::try_new("FN", "Mr. John Example")?,
Contentline::try_new("BDAY", "20230326")?
.try_add_param("VALUE", ["date-and-or-time"])?,
Contentline::try_new("END", "VCARD")?,
];
// For the sake of simplicity and testability, the vCard is written to a Vec. However, in a
// real application, one would probably write it to disk or do some further processing (e.g.
// compression)
let vcard = {
let mut buffer = Vec::new();
let mut writer = Writer::new(&mut buffer);
writer.write_all(contentlines)?;
buffer
};
let expected = "\
BEGIN:VCARD\r
FN:Mr. John Example\r
BDAY;VALUE=date-and-or-time:20230326\r
END:VCARD\r
".as_bytes();
assert_eq!(vcard, expected);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for Writer<W>where
W: Freeze,
impl<W> RefUnwindSafe for Writer<W>where
W: RefUnwindSafe,
impl<W> Send for Writer<W>where
W: Send,
impl<W> Sync for Writer<W>where
W: Sync,
impl<W> Unpin for Writer<W>where
W: Unpin,
impl<W> UnwindSafe for Writer<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more