From b5fe823dbddb0b5be3adc5f7b78cd31b07895095 Mon Sep 17 00:00:00 2001 From: sapient_cogbag Date: Sat, 17 Oct 2020 07:59:23 +0100 Subject: [PATCH] Added lifetime parameters to all the writing systems - this means we can write to arbitrary string refs and such - also bumped version (do not think this is a breaking change? all the tests compiled. nyaa --- Cargo.toml | 2 +- src/write/encoder.rs | 16 ++++++---- src/write/encoder_string_writer.rs | 50 ++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 30e73eec..d3cbf3ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "base64" -version = "0.13.0" +version = "0.13.1" authors = ["Alice Maz ", "Marshall Pierce "] description = "encodes and decodes base64 as bytes or utf8" repository = "https://github.com/marshallpierce/rust-base64" diff --git a/src/write/encoder.rs b/src/write/encoder.rs index 8a48f438..8d881029 100644 --- a/src/write/encoder.rs +++ b/src/write/encoder.rs @@ -53,7 +53,7 @@ const MIN_ENCODE_CHUNK_SIZE: usize = 3; /// /// It has some minor performance loss compared to encoding slices (a couple percent). /// It does not do any heap allocation. -pub struct EncoderWriter { +pub struct EncoderWriter<'a, W: Write + 'a> { config: Config, /// Where encoded data is written to. It's an Option as it's None immediately before Drop is /// called so that finish() can return the underlying writer. None implies that finish() has @@ -71,9 +71,12 @@ pub struct EncoderWriter { output_occupied_len: usize, /// panic safety: don't write again in destructor if writer panicked while we were writing to it panicked: bool, + /// We in some sense hold a "reference" to the writer inside. + /// tho we actually make it match delegate + _ref_lifetime: std::marker::PhantomData