Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
Fix ref_filter_map tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Mar 7, 2016
1 parent c58ebf8 commit b1a1240
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
RUST_CHANNEL ?= nightly

CRATES = matches show text_writer triable return_if_ok string-wrapper ref_filter_map
CRATES = matches show text_writer triable return_if_ok string-wrapper

# FIXME: Make this unconditional when 1.8 hits the stable channel.
# ref_filter_map uses Ref::map which is stable since 1.8
ifneq "$(RUST_CHANNEL)" "stable"
CRATES += ref_filter_map
endif

ifeq "$(RUST_CHANNEL)" "nightly"
CRATES += zip_longest
endif
Expand Down
2 changes: 1 addition & 1 deletion ref_filter_map/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ref_filter_map"
version = "1.0.0"
version = "1.0.1"
authors = ["Simon Sapin <[email protected]>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/SimonSapin/rust-std-candidates"
Expand Down
14 changes: 10 additions & 4 deletions ref_filter_map/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
//!
//! Internally they use a raw pointer and some `unsafe` code,
//! but the API they provide is believed to be safe.
//!
//! This was once part of `std::cell` but has been deprecated there since it makes `Option`
//! too much of a special case.
//!
//! https://github.com/rust-lang/rust/pull/25747
//! https://github.com/rust-lang/rust/issues/27746
use std::cell::{Ref, RefMut};

Expand All @@ -40,12 +46,12 @@ use std::cell::{Ref, RefMut};
/// # Example
///
/// ```
/// # #![feature(cell_extras)]
/// use std::cell::{RefCell, Ref};
/// use ref_filter_map::ref_filter_map;
///
/// let c = RefCell::new(Ok(5));
/// let b1: Ref<Result<u32, ()>> = c.borrow();
/// let b2: Ref<u32> = Ref::filter_map(b1, |o| o.as_ref().ok()).unwrap();
/// let b2: Ref<u32> = ref_filter_map(b1, |o| o.as_ref().ok()).unwrap();
/// assert_eq!(*b2, 5)
/// ```
pub fn ref_filter_map<
Expand All @@ -69,13 +75,13 @@ pub fn ref_filter_map<
/// # Example
///
/// ```
/// # #![feature(cell_extras)]
/// use std::cell::{RefCell, RefMut};
/// use ref_filter_map::ref_mut_filter_map;
///
/// let c = RefCell::new(Ok(5));
/// {
/// let b1: RefMut<Result<u32, ()>> = c.borrow_mut();
/// let mut b2: RefMut<u32> = RefMut::filter_map(b1, |o| o.as_mut().ok()).unwrap();
/// let mut b2: RefMut<u32> = ref_mut_filter_map(b1, |o| o.as_mut().ok()).unwrap();
/// assert_eq!(*b2, 5);
/// *b2 = 42;
/// }
Expand Down

0 comments on commit b1a1240

Please sign in to comment.