Skip to main content

Writer

Struct Writer 

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

Write 先へ効率よく出力するヘルパです。

値は内部の BufWriter に蓄積され、flush または Drop 時に 書き出されます。

Implementations§

Source§

impl<W: Write> Writer<W>

Source

pub fn with_writer(writer: W) -> Self

writer を出力先として作ります。

書き込みは内部バッファに蓄積されます。明示的に flush するか、値が破棄されると バッファが出力先へ書き出されます。

Source

pub fn print(&mut self, value: impl Display)

Display 可能な value を改行なしで出力バッファへ追加します。

書き込みに失敗した場合は panic します。

Source

pub fn println(&mut self, value: impl Display)

Display 可能な value と改行を出力バッファへ追加します。

書き込みに失敗した場合は panic します。

Source

pub fn print_yes_no(&mut self, condition: bool)

condition が true なら Yes、false なら No を改行付きで出力します。

Source

pub fn print_yes(&mut self)

Yes を改行付きで出力します。

Source

pub fn print_no(&mut self)

No を改行付きで出力します。

Source

pub fn join<T: Display>( &mut self, values: impl IntoIterator<Item = T>, separator: &str, )

values の各要素を separator で連結し、末尾に改行を出力します。

空イテレータの場合も改行を1つ出力します。イテレータの要素数を N、値と区切り文字の 合計出力バイト数を S とすると、時間計算量は O(N + S) です。

Source

pub fn join_nospace<T: Display>(&mut self, values: impl IntoIterator<Item = T>)

values の要素を区切りなしで連結し、末尾に改行を付けて出力します。

Source

pub fn join_whitespace<T: Display>( &mut self, values: impl IntoIterator<Item = T>, )

values の要素を ASCII 空白1文字で区切り、末尾に改行を付けて出力します。

Source

pub fn join_line<T: Display>(&mut self, values: impl IntoIterator<Item = T>)

values の要素を改行で区切って出力し、最後にも改行を付けます。

Source

pub fn flush(&mut self)

バッファの内容を出力先へ書き出します。

書き込みに失敗した場合は panic します。

Source§

impl Writer<StdoutLock<'static>>

Source

pub fn new() -> Self

標準出力を出力先として作ります。

標準出力をロックしてラップします。出力を明示的に確定したい場合は flush を呼びます。

Trait Implementations§

Source§

impl Default for Writer<StdoutLock<'static>>

Source§

fn default() -> Self

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

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> UnsafeUnpin for Writer<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for Writer<W>
where W: 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>,

Source§

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>,

Source§

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.