Skip to content

Commit 136c273

Browse files
kpcyrdchifflier
authored andcommitted
Fix doctests with --no-default-features
1 parent 82c2acd commit 136c273

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- --all-features
4545
- --features=bigint,serialize,debug
4646
- --features=bigint,serialize,trace
47+
- --no-default-features
4748
steps:
4849
- uses: actions/checkout@v4
4950
- name: Install stable toolchain

src/asn1_types/integer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ impl_int!(u128 => i128);
276276
///
277277
/// Encoding an `Integer` to DER
278278
///
279-
/// ```
279+
#[cfg_attr(feature = "std", doc = r#"```"#)]
280+
#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
280281
/// use asn1_rs::{Integer, ToDer};
281282
///
282283
/// let i = Integer::from(4);

src/asn1_types/sequence.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub use sequence_of::*;
2828
/// - if the sequence is composed of objects of the same type, the [`Sequence::from_iter_to_der`] method can be used
2929
/// - otherwise, the [`ToDer`] trait can be used to create content incrementally
3030
///
31-
/// ```
31+
#[cfg_attr(feature = "std", doc = r#"```"#)]
32+
#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
3233
/// use asn1_rs::{Integer, Sequence, SerializeResult, ToDer};
3334
///
3435
/// fn build_seq<'a>() -> SerializeResult<Sequence<'a>> {
@@ -48,7 +49,8 @@ pub use sequence_of::*;
4849
///
4950
/// # Examples
5051
///
51-
/// ```
52+
#[cfg_attr(feature = "std", doc = r#"```"#)]
53+
#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
5254
/// use asn1_rs::{Error, Sequence};
5355
///
5456
/// // build sequence

src/asn1_types/set.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub use set_of::*;
2929
/// - if the set is composed of objects of the same type, the [`Set::from_iter_to_der`] method can be used
3030
/// - otherwise, the [`ToDer`] trait can be used to create content incrementally
3131
///
32-
/// ```
32+
#[cfg_attr(feature = "std", doc = r#"```"#)]
33+
#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
3334
/// use asn1_rs::{Integer, Set, SerializeResult, ToDer};
3435
///
3536
/// fn build_set<'a>() -> SerializeResult<Set<'a>> {
@@ -49,7 +50,8 @@ pub use set_of::*;
4950
///
5051
/// # Examples
5152
///
52-
/// ```
53+
#[cfg_attr(feature = "std", doc = r#"```"#)]
54+
#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
5355
/// use asn1_rs::{Error, Set};
5456
///
5557
/// // build set

src/derive.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ pub use asn1_rs_derive::ToStatic;
375375
///
376376
/// Define a structure and add the `DerSequence` derive:
377377
///
378-
/// ```rust
378+
#[cfg_attr(feature = "std", doc = r#"```rust"#)]
379+
#[cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
379380
/// use asn1_rs::*;
380381
///
381382
/// #[derive(DerSequence, ToDerSequence)]

src/doc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#[doc = include_str!("../../doc/RECIPES.md")]
44
pub mod recipes {}
55

6+
#[cfg(feature = "std")]
67
#[doc = include_str!("../../doc/DERIVE.md")]
78
pub mod derive {}
89

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
//!
102102
//! Writing 2 BER integers:
103103
//!
104-
//! ```rust
104+
#![cfg_attr(feature = "std", doc = r#"```rust"#)]
105+
#![cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
105106
//! use asn1_rs::{Integer, ToDer};
106107
//!
107108
//! let mut writer = Vec::new();
@@ -120,7 +121,8 @@
120121
//!
121122
//! Similarly to `FromBer`/`FromDer`, serialization methods are also implemented for primitive types:
122123
//!
123-
//! ```rust
124+
#![cfg_attr(feature = "std", doc = r#"```rust"#)]
125+
#![cfg_attr(not(feature = "std"), doc = r#"```rust,compile_fail"#)]
124126
//! use asn1_rs::ToDer;
125127
//!
126128
//! let mut writer = Vec::new();

0 commit comments

Comments
 (0)