Skip to content

Commit bca0558

Browse files
committed
Guard tests that depend on 'std' feature with conditional compilation
1 parent 1caf7c7 commit bca0558

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

src/double_priority_queue/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ where
473473
///
474474
/// # Example
475475
/// ```
476+
/// # #[cfg(feature = "std")] {
476477
/// # use priority_queue::DoublePriorityQueue;
477478
/// let mut pq = DoublePriorityQueue::new();
478479
///
@@ -486,6 +487,7 @@ where
486487
///
487488
/// assert_eq!(pq.peek_min(), Some((&"Bananas", &15)));
488489
/// assert_eq!(pq.into_vec(), vec!["Bananas"]);
490+
/// # }
489491
/// ```
490492
pub fn extract_if<F>(&mut self, predicate: F) -> ExtractIf<I, P, F, H>
491493
where
@@ -512,6 +514,7 @@ where
512514
///
513515
/// # Example
514516
/// ```
517+
/// # #[cfg(feature = "std")] {
515518
/// # use priority_queue::DoublePriorityQueue;
516519
/// let mut pq = DoublePriorityQueue::new();
517520
///
@@ -524,6 +527,7 @@ where
524527
/// }), None);
525528
///
526529
/// assert_eq!(pq.pop_min(), Some(("Bananas", 10)));
530+
/// # }
527531
/// ```
528532
pub fn pop_min_if<F>(&mut self, f: F) -> Option<(I, P)>
529533
where
@@ -554,6 +558,7 @@ where
554558
///
555559
/// # Example
556560
/// ```
561+
/// # #[cfg(feature = "std")] {
557562
/// # use priority_queue::DoublePriorityQueue;
558563
/// let mut pq = DoublePriorityQueue::new();
559564
/// pq.push("Apples", 5);
@@ -563,6 +568,7 @@ where
563568
/// false
564569
/// }), None);
565570
/// assert_eq!(pq.pop_max(), Some(("Apples", 5)));
571+
/// # }
566572
/// ```
567573
pub fn pop_max_if<F>(&mut self, f: F) -> Option<(I, P)>
568574
where
@@ -583,6 +589,7 @@ where
583589
///
584590
/// # Example
585591
/// ```
592+
/// # #[cfg(feature = "std")] {
586593
/// # use priority_queue::DoublePriorityQueue;
587594
/// let mut pq = DoublePriorityQueue::new();
588595
/// assert_eq!(pq.push("Apples", 5), None);
@@ -591,6 +598,7 @@ where
591598
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
592599
/// assert_eq!(pq.push("Apples", 4), Some(6));
593600
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
601+
/// # }
594602
/// ```
595603
///
596604
/// Computes in **O(log(N))** time.
@@ -641,6 +649,7 @@ where
641649
///
642650
/// # Example
643651
/// ```
652+
/// # #[cfg(feature = "std")] {
644653
/// # use priority_queue::DoublePriorityQueue;
645654
/// let mut pq = DoublePriorityQueue::new();
646655
/// assert_eq!(pq.push_increase("Apples", 5), None);
@@ -651,6 +660,7 @@ where
651660
/// // priority is returned.
652661
/// assert_eq!(pq.push_increase("Apples", 4), Some(4));
653662
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
663+
/// # }
654664
/// ```
655665
///
656666
/// Computes in **O(log(N))** time.
@@ -679,6 +689,7 @@ where
679689
///
680690
/// # Example
681691
/// ```
692+
/// # #[cfg(feature = "std")] {
682693
/// # use priority_queue::DoublePriorityQueue;
683694
/// let mut pq = DoublePriorityQueue::new();
684695
/// assert_eq!(pq.push_decrease("Apples", 5), None);
@@ -689,6 +700,7 @@ where
689700
/// // priority is returned.
690701
/// assert_eq!(pq.push_decrease("Apples", 6), Some(6));
691702
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
703+
/// # }
692704
/// ```
693705
///
694706
/// Computes in **O(log(N))** time.
@@ -708,6 +720,7 @@ where
708720
///
709721
/// # Example
710722
/// ```
723+
/// # #[cfg(feature = "std")] {
711724
/// # use priority_queue::DoublePriorityQueue;
712725
/// let mut pq = DoublePriorityQueue::new();
713726
/// assert_eq!(pq.change_priority("Apples", 5), None);
@@ -716,6 +729,7 @@ where
716729
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
717730
/// assert_eq!(pq.change_priority("Apples", 4), Some(6));
718731
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
732+
/// # }
719733
/// ```
720734
///
721735
/// The item is found in **O(1)** thanks to the hash table.

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
//!
5555
//! # Examples
5656
//! ```rust
57+
//! # #[cfg(feature = "std")] {
5758
//! use priority_queue::PriorityQueue;
5859
//!
5960
//! let mut pq = PriorityQueue::new();
@@ -71,10 +72,12 @@
7172
//! for (item, _) in pq.into_sorted_iter() {
7273
//! println!("{}", item); // Will print Bananas, Strawberries, Apples
7374
//! }
75+
//! # }
7476
//! ```
7577
//!
7678
//! ## Reverse ordering
7779
//! ```rust
80+
//! # #[cfg(feature = "std")] {
7881
//! use priority_queue::PriorityQueue;
7982
//! use std::cmp::Reverse;
8083
//!
@@ -90,6 +93,7 @@
9093
//! for (item, _) in pq.into_sorted_iter() {
9194
//! println!("{}", item); // Will print Apples, Bananas, Strawberries
9295
//! }
96+
//! # }
9397
//! ```
9498
//!
9599
//! # Crate features

src/priority_queue/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use std::mem::replace;
6262
///
6363
/// # Example
6464
/// ```rust
65+
/// # #[cfg(feature = "std")] {
6566
/// use priority_queue::PriorityQueue;
6667
///
6768
/// let mut pq = PriorityQueue::new();
@@ -79,6 +80,7 @@ use std::mem::replace;
7980
/// for (item, _) in pq.into_sorted_iter() {
8081
/// println!("{}", item);
8182
/// }
83+
/// # }
8284
/// ```
8385
#[derive(Clone, Debug)]
8486
#[cfg(feature = "std")]
@@ -383,6 +385,7 @@ where
383385
///
384386
/// # Example
385387
/// ```
388+
/// # #[cfg(feature = "std")] {
386389
/// # use priority_queue::PriorityQueue;
387390
/// let mut pq = PriorityQueue::new();
388391
///
@@ -396,6 +399,7 @@ where
396399
///
397400
/// assert_eq!(pq.peek(), Some((&"Bananas", &15)));
398401
/// assert_eq!(pq.into_vec(), vec!["Bananas"]);
402+
/// # }
399403
/// ```
400404
pub fn extract_if<F>(&mut self, predicate: F) -> ExtractIf<I, P, F, H>
401405
where
@@ -422,6 +426,7 @@ where
422426
///
423427
/// # Example
424428
/// ```
429+
/// # #[cfg(feature = "std")] {
425430
/// # use priority_queue::PriorityQueue;
426431
/// let mut pq = PriorityQueue::new();
427432
///
@@ -434,6 +439,7 @@ where
434439
/// }), None);
435440
///
436441
/// assert_eq!(pq.pop(), Some(("Apples", 5)));
442+
/// # }
437443
/// ```
438444
pub fn pop_if<F>(&mut self, predicate: F) -> Option<(I, P)>
439445
where
@@ -458,6 +464,7 @@ where
458464
///
459465
/// # Example
460466
/// ```
467+
/// # #[cfg(feature = "std")] {
461468
/// # use priority_queue::PriorityQueue;
462469
/// let mut pq = PriorityQueue::new();
463470
/// assert_eq!(pq.push("Apples", 5), None);
@@ -466,6 +473,7 @@ where
466473
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
467474
/// assert_eq!(pq.push("Apples", 4), Some(6));
468475
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
476+
/// # }
469477
/// ```
470478
///
471479
/// Computes in **O(log(N))** time.
@@ -515,6 +523,7 @@ where
515523
///
516524
/// # Example
517525
/// ```
526+
/// # #[cfg(feature = "std")] {
518527
/// # use priority_queue::PriorityQueue;
519528
/// let mut pq = PriorityQueue::new();
520529
/// assert_eq!(pq.push_increase("Apples", 5), None);
@@ -525,6 +534,7 @@ where
525534
/// // priority is returned.
526535
/// assert_eq!(pq.push_increase("Apples", 4), Some(4));
527536
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
537+
/// # }
528538
/// ```
529539
///
530540
/// Computes in **O(log(N))** time.
@@ -553,6 +563,7 @@ where
553563
///
554564
/// # Example
555565
/// ```
566+
/// # #[cfg(feature = "std")] {
556567
/// # use priority_queue::PriorityQueue;
557568
/// let mut pq = PriorityQueue::new();
558569
/// assert_eq!(pq.push_decrease("Apples", 5), None);
@@ -563,6 +574,7 @@ where
563574
/// // priority is returned.
564575
/// assert_eq!(pq.push_decrease("Apples", 6), Some(6));
565576
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
577+
/// # }
566578
/// ```
567579
///
568580
/// Computes in **O(log(N))** time.
@@ -582,6 +594,7 @@ where
582594
///
583595
/// # Example
584596
/// ```
597+
/// # #[cfg(feature = "std")] {
585598
/// # use priority_queue::PriorityQueue;
586599
/// let mut pq = PriorityQueue::new();
587600
/// assert_eq!(pq.change_priority("Apples", 5), None);
@@ -590,6 +603,7 @@ where
590603
/// assert_eq!(pq.get_priority("Apples"), Some(&6));
591604
/// assert_eq!(pq.change_priority("Apples", 4), Some(6));
592605
/// assert_eq!(pq.get_priority("Apples"), Some(&4));
606+
/// # }
593607
/// ```
594608
///
595609
/// The item is found in **O(1)** thanks to the hash table.

tests/double_priority_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* obtain one at http://mozilla.org/MPL/2.0/.
2626
*
2727
*/
28-
28+
#[cfg(feature = "std")]
2929
#[cfg(test)]
3030
mod doublepq_tests {
3131
pub use priority_queue::DoublePriorityQueue;

tests/priority_queue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*
2727
*/
2828

29+
#[cfg(feature = "std")]
2930
#[cfg(test)]
3031
mod pqueue_tests {
3132
pub use priority_queue::PriorityQueue;

0 commit comments

Comments
 (0)