Skip to content

Commit

Permalink
Merge pull request #273 from alexpovel/master
Browse files Browse the repository at this point in the history
Documentation example for constant-space validity checking
  • Loading branch information
marshallpierce authored Aug 5, 2024
2 parents e144006 + 5664c35 commit 77e5251
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,33 @@
//! # }
//! ```
//!
//! This also allows for constant-space validity checking of encoded data, using a
//! statically allocated buffer:
//!
#![cfg_attr(feature = "std", doc = "```")]
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
//! # use std::io::{self, Read};
//! use base64::{engine::general_purpose::STANDARD, read::DecoderReader};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut invalid_input = "dt==";
//! let mut decoder = DecoderReader::new(io::Cursor::new(&mut invalid_input), &STANDARD);
//!
//! let mut buf = [0u8; 128];
//!
//! let is_valid = loop {
//! match decoder.read(&mut buf) {
//! Ok(0) => break true, // Read to end w/o error
//! Ok(_) => continue,
//! Err(_) => break false,
//! }
//! };
//!
//! assert!(!is_valid);
//! # Ok(())
//! # }
//! ```
//!
//! #### Encoding
//!
#![cfg_attr(feature = "std", doc = "```")]
Expand Down

0 comments on commit 77e5251

Please sign in to comment.