mirror of https://github.com/ctz/rustls
Add WriteV implementation for any Write objects
Adds a WriteVAdapter which takes a std::io::Write object and makes it compatible with the WriteV trait
This commit is contained in:
parent
21642466a3
commit
f022189734
|
@ -277,7 +277,7 @@ pub use crate::verify::{NoClientAuth, AllowAnyAuthenticatedClient,
|
|||
pub use crate::suites::{ALL_CIPHERSUITES, BulkAlgorithm, SupportedCipherSuite};
|
||||
pub use crate::key::{Certificate, PrivateKey};
|
||||
pub use crate::keylog::{KeyLog, NoKeyLog, KeyLogFile};
|
||||
pub use crate::vecbuf::WriteV;
|
||||
pub use crate::vecbuf::{WriteV, WriteVAdapter};
|
||||
|
||||
/// Message signing interfaces and implementations.
|
||||
pub mod sign;
|
||||
|
|
|
@ -154,6 +154,30 @@ impl ChunkVecBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
/// This is a simple wrapper around an object
|
||||
/// which implements `std::io::Write` in order to autoimplement `WriteV`.
|
||||
/// It uses the `write_vectored` method from `std::io::Write` in order
|
||||
/// to do this.
|
||||
pub struct WriteVAdapter<T: io::Write>(T);
|
||||
|
||||
impl<T: io::Write> WriteVAdapter<T> {
|
||||
/// build an adapter from a Write object
|
||||
pub fn new(inner: T) -> Self {
|
||||
WriteVAdapter(inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: io::Write> WriteV for WriteVAdapter<T> {
|
||||
fn writev(&mut self, buffers: &[&[u8]]) -> io::Result<usize> {
|
||||
self.0.write_vectored(
|
||||
&buffers
|
||||
.iter()
|
||||
.map(|b| io::IoSlice::new(b))
|
||||
.collect::<Vec<io::IoSlice>>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::ChunkVecBuffer;
|
||||
|
|
Loading…
Reference in New Issue