Trait WriteIntoCString

Source
pub trait WriteIntoCString {
    // Required method
    fn write_into<F>(&mut self, func: F) -> Result<()>
       where F: FnOnce(&mut CStringWriter) -> Result<()>;
}
Expand description

§Extension trait to enable Write on CString

It receives a closure that takes a CStringWriter and stores the write result in the instance (replacing any previous content).

If the written data contains NUL bytes, an error is returned.

§Example:

use std::ffi::CString;
use std::io::Write;
use falco_plugin::strings::WriteIntoCString;
let mut buf = CString::default();

buf.write_into(|w| write!(w, "hello")).unwrap();

assert_eq!(buf.as_c_str(), c"hello");

Required Methods§

Source

fn write_into<F>(&mut self, func: F) -> Result<()>
where F: FnOnce(&mut CStringWriter) -> Result<()>,

Write into a std::ffi::CString using std::io::Write

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl WriteIntoCString for CString

Source§

fn write_into<F>(&mut self, func: F) -> Result<()>
where F: FnOnce(&mut CStringWriter) -> Result<()>,

Implementors§