pub struct Writer<T: Write> { /* private fields */ }
Expand description
Writer for the HepMC2 format
Implementations§
source§impl<T: Default + Write> Writer<T>
impl<T: Default + Write> Writer<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Retrieve the underlying writer
source§impl<T: Write> Writer<T>
impl<T: Write> Writer<T>
sourcepub fn new(stream: T) -> Result<Self, Error>
pub fn new(stream: T) -> Result<Self, Error>
Construct new Writer
This automatically tries to write the mandatory HepMC header, which may fail.
§Example
use hepmc2::writer::Writer;
let mut output = Vec::new();
let mut writer = Writer::new(&mut output)?;
// always call finish at the end
writer.finish()?;
ⓘ
use hepmc2::writer::Writer;
let mut output = Vec::new();
let mut writer = Writer::new(&mut output).await.unwrap();
// always call finish at the end
writer.finish().await.unwrap();
sourcepub fn with_header<U: Display>(stream: T, header: U) -> Result<Self, Error>
pub fn with_header<U: Display>(stream: T, header: U) -> Result<Self, Error>
Construct new Writer
, trying to write a custom header
hepmc2
ignores headers, but other implementations of the
format may be less lenient.
§Example
§Sync
use hepmc2::writer::Writer;
let mut output = Vec::new();
let mut writer = Writer::with_header(output, "")?;
// always call finish at the end
writer.finish()?;
§Async
ⓘ
use hepmc2::writer::Writer;
let mut output = Vec::new();
let mut writer = Writer::with_header(output, "").await.unwrap();
// always call finish at the end
writer.finish().await.unwrap();
sourcepub fn finish(self) -> Result<(), Error>
pub fn finish(self) -> Result<(), Error>
Finish writing, consuming the Writer
This tries to write the mandatory HepMC footer, which may fail.
§Example
§Sync
use hepmc2::writer::Writer;
let mut output = Vec::new();
let mut writer = Writer::new(&mut output)?;
// always call finish at the end
writer.finish()?;
§Async
ⓘ
use hepmc2::writer::Writer;
let mut output = Vec::new();
let mut writer = Writer::new(&mut output).await.unwrap();
// always call finish at the end
writer.finish().await.unwrap();
sourcepub fn write(&mut self, event: &Event) -> Result<(), Error>
pub fn write(&mut self, event: &Event) -> Result<(), Error>
Write an event
§Example
§Sync
use hepmc2::writer::Writer;
use hepmc2::event::Event;
let mut output = Vec::new();
let mut writer = Writer::new(&mut output)?;
let event = Event::default();
writer.write(&event)?;
// always call finish at the end
writer.finish()?;
§Async
ⓘ
use hepmc2::writer::Writer;
use hepmc2::event::Event;
let mut output = Vec::new();
let mut writer = Writer::new(&mut output).await.unwrap();
let event = Event::default();
writer.write(&event).await.unwrap();
// always call finish at the end
writer.finish().await.unwrap();
pub fn try_from(stream: T) -> Result<Self, Error>
Trait Implementations§
source§impl<T: Ord + Write> Ord for Writer<T>
impl<T: Ord + Write> Ord for Writer<T>
source§impl<T: PartialEq + Write> PartialEq for Writer<T>
impl<T: PartialEq + Write> PartialEq for Writer<T>
source§impl<T: PartialOrd + Write> PartialOrd for Writer<T>
impl<T: PartialOrd + Write> PartialOrd for Writer<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Eq + Write> Eq for Writer<T>
impl<T: Write> StructuralPartialEq for Writer<T>
Auto Trait Implementations§
impl<T> Freeze for Writer<T>where
T: Freeze,
impl<T> RefUnwindSafe for Writer<T>where
T: RefUnwindSafe,
impl<T> Send for Writer<T>where
T: Send,
impl<T> Sync for Writer<T>where
T: Sync,
impl<T> Unpin for Writer<T>where
T: Unpin,
impl<T> UnwindSafe for Writer<T>where
T: 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