Struct vcd::Writer

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

Struct wrapping an std::io::Write with methods for writing VCD commands and data.

Example

use std::{fs::File, io::BufWriter};
use vcd::{Value, TimescaleUnit};
 
let mut writer = vcd::Writer::new(BufWriter::new(File::create("test.vcd")?));
 
writer.timescale(1, TimescaleUnit::US)?;
writer.add_module("top")?;
let clock = writer.add_wire(1, "clock")?;
writer.upscope()?;
writer.enddefinitions()?;
 
let mut t = 0;
while t < 100 {
    writer.timestamp(t)?;
    writer.change_scalar(clock, Value::V0)?;
    t += 2;
 
    writer.timestamp(t)?;
    writer.change_scalar(clock, Value::V1)?;
    t += 2;
}

Implementations§

source§

impl<W: Write> Writer<W>

source

pub fn new(writer: W) -> Writer<W>

Creates a Writer wrapping an io::Write.

let mut buf = Vec::new();
let mut vcd = vcd::Writer::new(&mut buf);
source

pub fn writer(&mut self) -> &mut W

Get the wrapped io::Write.

source

pub fn flush(&mut self) -> Result<()>

Flush the wrapped io::Write.

source

pub fn header(&mut self, h: &Header) -> Result<()>

Writes a complete header with the fields from a Header struct from the parser.

source

pub fn comment(&mut self, v: &str) -> Result<()>

Writes a $comment command.

source

pub fn date(&mut self, v: &str) -> Result<()>

Writes a $date command.

source

pub fn version(&mut self, v: &str) -> Result<()>

Writes a $version command.

source

pub fn timescale(&mut self, ts: u32, unit: TimescaleUnit) -> Result<()>

Writes a $timescale command.

source

pub fn scope_def(&mut self, t: ScopeType, i: &str) -> Result<()>

Writes a $scope command.

source

pub fn add_module(&mut self, identifier: &str) -> Result<()>

Writes a $scope command for a module.

Convenience wrapper around Writer::scope_def.

source

pub fn upscope(&mut self) -> Result<()>

Writes an $upscope command.

source

pub fn scope(&mut self, s: &Scope) -> Result<()>

Writes a $scope command, a series of $var commands, and an $upscope commands from a Scope structure from the parser.

source

pub fn var_def( &mut self, var_type: VarType, width: u32, id: IdCode, reference: &str, index: Option<ReferenceIndex> ) -> Result<()>

Writes a $var command with a specified id.

source

pub fn add_var( &mut self, var_type: VarType, width: u32, reference: &str, index: Option<ReferenceIndex> ) -> Result<IdCode>

Writes a $var command with the next available ID, returning the assigned ID.

Convenience wrapper around Writer::var_def.

source

pub fn add_wire(&mut self, width: u32, reference: &str) -> Result<IdCode>

Adds a $var for a wire with the next available ID, returning the assigned ID.

Convenience wrapper around Writer::add_var.

source

pub fn var(&mut self, v: &Var) -> Result<()>

Writes a $var command from a Var structure from the parser.

source

pub fn enddefinitions(&mut self) -> Result<()>

Writes a $enddefinitions command to end the header.

source

pub fn timestamp(&mut self, ts: u64) -> Result<()>

Writes a #xxx timestamp.

source

pub fn change_scalar<V: Into<Value>>(&mut self, id: IdCode, v: V) -> Result<()>

Writes a change to a scalar variable.

source

pub fn change_vector( &mut self, id: IdCode, v: impl IntoIterator<Item = Value> ) -> Result<()>

Writes a change to a vector variable.

source

pub fn change_real(&mut self, id: IdCode, v: f64) -> Result<()>

Writes a change to a real variable.

source

pub fn change_string(&mut self, id: IdCode, v: &str) -> Result<()>

Writes a change to a string variable.

source

pub fn begin(&mut self, c: SimulationCommand) -> Result<()>

Writes the beginning of a simulation command.

source

pub fn end(&mut self) -> Result<()>

Writes an $end to end a simulation command.

source

pub fn command(&mut self, c: &Command) -> Result<()>

Writes a command from a Command enum as parsed by the parser.

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.