Struct hepmc2::writer::Writer

source ·
pub struct Writer<T: Write> { /* private fields */ }
Expand description

Writer for the HepMC2 format

Implementations§

source§

impl<T: Default + Write> Writer<T>

source

pub fn into_inner(self) -> T

Retrieve the underlying writer

source§

impl<T: Write> Writer<T>

source

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();
source

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();
source

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();
source

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();
source

pub fn try_from(stream: T) -> Result<Self, Error>

Trait Implementations§

source§

impl<T: Debug + Write> Debug for Writer<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default + Write> Default for Writer<T>

source§

fn default() -> Writer<T>

Returns the “default value” for a type. Read more
source§

impl<T: Write> Drop for Writer<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: Hash + Write> Hash for Writer<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Ord + Write> Ord for Writer<T>

source§

fn cmp(&self, other: &Writer<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq + Write> PartialEq for Writer<T>

source§

fn eq(&self, other: &Writer<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + Write> PartialOrd for Writer<T>

source§

fn partial_cmp(&self, other: &Writer<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Eq + Write> Eq for Writer<T>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.