Movatterモバイル変換


[0]ホーム

URL:


Write

std::fmt

TraitWrite 

1.0.0 ·Source
pub trait Write {    // Required method    fnwrite_str(&mut self, s: &str) ->Result<(),Error>;    // Provided methods    fnwrite_char(&mut self, c:char) ->Result<(),Error> { ... }    fnwrite_fmt(&mut self, args:Arguments<'_>) ->Result<(),Error> { ... }}
Expand description

A trait for writing or formatting into Unicode-accepting buffers or streams.

This trait only accepts UTF-8–encoded data and is notflushable. If you onlywant to accept Unicode and you don’t need flushing, you should implement this trait;otherwise you should implementstd::io::Write.

Required Methods§

1.0.0 ·Source

fnwrite_str(&mut self, s: &str) ->Result<(),Error>

Writes a string slice into this writer, returning whether the writesucceeded.

This method can only succeed if the entire string slice was successfullywritten, and this method will not return until all data has beenwritten or an error occurs.

§Errors

This function will return an instance ofstd::fmt::Error on error.

The purpose of that error is to abort the formatting operation when the underlyingdestination encounters some error preventing it from accepting more text;in particular, it does not communicate any information aboutwhat error occurred.It should generally be propagated rather than handled, at least when implementingformatting traits.

§Examples
usestd::fmt::{Error, Write};fnwriter<W: Write>(f:&mutW, s:&str) ->Result<(), Error> {    f.write_str(s)}letmutbuf = String::new();writer(&mutbuf,"hola")?;assert_eq!(&buf,"hola");

Provided Methods§

1.1.0 ·Source

fnwrite_char(&mut self, c:char) ->Result<(),Error>

Writes achar into this writer, returning whether the write succeeded.

A singlechar may be encoded as more than one byte.This method can only succeed if the entire byte sequence was successfullywritten, and this method will not return until all data has beenwritten or an error occurs.

§Errors

This function will return an instance ofError on error.

§Examples
usestd::fmt::{Error, Write};fnwriter<W: Write>(f:&mutW, c: char) ->Result<(), Error> {    f.write_char(c)}letmutbuf = String::new();writer(&mutbuf,'a')?;writer(&mutbuf,'b')?;assert_eq!(&buf,"ab");
1.0.0 ·Source

fnwrite_fmt(&mut self, args:Arguments<'_>) ->Result<(),Error>

Glue for usage of thewrite! macro with implementors of this trait.

This method should generally not be invoked manually, but rather throughthewrite! macro itself.

§Errors

This function will return an instance ofError on error. Please seewrite_str for details.

§Examples
usestd::fmt::{Error, Write};fnwriter<W: Write>(f:&mutW, s:&str) ->Result<(), Error> {    f.write_fmt(format_args!("{s}"))}letmutbuf = String::new();writer(&mutbuf,"world")?;assert_eq!(&buf,"world");

Implementors§

1.64.0 ·Source§

implWrite forOsString

1.0.0 ·Source§

implWrite forString

1.2.0 ·Source§

implWrite forFormatter<'_>

1.4.0 ·Source§

impl<W>Write for&mut W
where W:Write + ?Sized,


[8]ページ先頭

©2009-2025 Movatter.jp