|
29 | 29 | //! The original description in [BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki)
|
30 | 30 | //! has more details.
|
31 | 31 | //!
|
32 |
| -//! # Examples |
33 |
| -//! |
34 |
| -//! ``` |
35 |
| -//! use bech32::{self, FromBase32, ToBase32, Variant}; |
36 |
| -//! |
37 |
| -//! let encoded = bech32::encode("bech32", vec![0x00, 0x01, 0x02].to_base32(), Variant::Bech32).unwrap(); |
38 |
| -//! assert_eq!(encoded, "bech321qqqsyrhqy2a".to_string()); |
39 |
| -//! |
40 |
| -//! let (hrp, data, variant) = bech32::decode(&encoded).unwrap(); |
41 |
| -//! assert_eq!(hrp, "bech32"); |
42 |
| -//! assert_eq!(Vec::<u8>::from_base32(&data).unwrap(), vec![0x00, 0x01, 0x02]); |
43 |
| -//! assert_eq!(variant, Variant::Bech32); |
44 |
| -//! ``` |
| 32 | +#![cfg_attr( |
| 33 | + feature = "std", |
| 34 | + doc = " |
| 35 | +# Examples |
| 36 | +``` |
| 37 | +use bech32::{self, FromBase32, ToBase32, Variant}; |
| 38 | +let encoded = bech32::encode(\"bech32\", vec![0x00, 0x01, 0x02].to_base32(), Variant::Bech32).unwrap(); |
| 39 | +assert_eq!(encoded, \"bech321qqqsyrhqy2a\".to_string()); |
| 40 | +let (hrp, data, variant) = bech32::decode(&encoded).unwrap(); |
| 41 | +assert_eq!(hrp, \"bech32\"); |
| 42 | +assert_eq!(Vec::<u8>::from_base32(&data).unwrap(), vec![0x00, 0x01, 0x02]); |
| 43 | +assert_eq!(variant, Variant::Bech32); |
| 44 | +``` |
| 45 | +" |
| 46 | +)] |
45 | 47 | //!
|
46 | 48 |
|
47 | 49 | // Allow trait objects without dyn on nightly and make 1.22 ignore the unknown lint
|
|
53 | 55 | #![deny(non_snake_case)]
|
54 | 56 | #![deny(unused_mut)]
|
55 | 57 | #![cfg_attr(feature = "strict", deny(warnings))]
|
| 58 | +#![cfg_attr(all(not(feature = "std"), not(test)), no_std)] |
| 59 | + |
| 60 | +#[cfg(all(not(feature = "std"), not(test)))] |
| 61 | +extern crate alloc; |
| 62 | + |
| 63 | +#[cfg(any(test, feature = "std"))] |
| 64 | +extern crate core; |
| 65 | + |
| 66 | +#[cfg(all(not(feature = "std"), not(test)))] |
| 67 | +use alloc::{string::String, vec::Vec}; |
56 | 68 |
|
| 69 | +#[cfg(all(not(feature = "std"), not(test)))] |
| 70 | +use alloc::borrow::Cow; |
| 71 | +#[cfg(any(feature = "std", test))] |
57 | 72 | use std::borrow::Cow;
|
58 |
| -use std::{error, fmt}; |
59 | 73 |
|
60 |
| -// AsciiExt is needed for Rust 1.14 but not for newer versions |
61 |
| -#[allow(unused_imports, deprecated)] |
62 |
| -use std::ascii::AsciiExt; |
| 74 | +use core::{fmt, mem}; |
63 | 75 |
|
64 | 76 | /// Integer in the range `0..32`
|
65 | 77 | #[derive(PartialEq, Eq, Debug, Copy, Clone, Default, PartialOrd, Ord, Hash)]
|
@@ -169,7 +181,7 @@ impl<'a> Bech32Writer<'a> {
|
169 | 181 | /// Write out the checksum at the end. If this method isn't called this will happen on drop.
|
170 | 182 | pub fn finalize(mut self) -> fmt::Result {
|
171 | 183 | self.inner_finalize()?;
|
172 |
| - std::mem::forget(self); |
| 184 | + mem::forget(self); |
173 | 185 | Ok(())
|
174 | 186 | }
|
175 | 187 |
|
@@ -626,7 +638,8 @@ impl fmt::Display for Error {
|
626 | 638 | }
|
627 | 639 | }
|
628 | 640 |
|
629 |
| -impl error::Error for Error { |
| 641 | +#[cfg(any(feature = "std", test))] |
| 642 | +impl std::error::Error for Error { |
630 | 643 | fn description(&self) -> &str {
|
631 | 644 | match *self {
|
632 | 645 | Error::MissingSeparator => "missing human-readable separator",
|
|
0 commit comments