Skip to content

Commit

Permalink
Add std feature and std::error::Error impl
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jan 11, 2024
1 parent d8817fb commit 19644ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ rust-version = "1.65"
[dependencies]
typenum = "1.17"
zeroize = { version = "1.7", optional = true }

[features]
std = []
14 changes: 13 additions & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
//! functionality.

use crate::{Array, ArraySize};
use core::slice::{Iter, IterMut};
use core::{
fmt,
slice::{Iter, IterMut},
};

/// Couldn't construct an array from an iterator because the number of items in the iterator
/// didn't match the array size.
#[derive(Clone, Copy, Debug)]
pub struct TryFromIteratorError;

impl fmt::Display for TryFromIteratorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("iterator did not contain the correct number of items for the array size")
}
}

#[cfg(feature = "std")]
impl std::error::Error for TryFromIteratorError {}

impl<T, U> Array<T, U>
where
U: ArraySize,
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
Expand All @@ -23,6 +23,9 @@
unused_qualifications
)]

#[cfg(feature = "std")]
extern crate std;

mod from_fn;
mod iter;
mod sizes;
Expand Down

0 comments on commit 19644ec

Please sign in to comment.