Replace use of unstable Option::flatten() with and_then()

This commit is contained in:
Dirkjan Ochtman 2019-08-26 21:26:10 +02:00
parent ca11dc2031
commit ce0113eb19
5 changed files with 4 additions and 8 deletions

View File

@ -59,7 +59,7 @@ fn save(
// If there is no filename, check the metadata for the origin filename // If there is no filename, check the metadata for the origin filename
if input.len() > 0 { if input.len() > 0 {
let origin = input[0].origin(); let origin = input[0].origin();
match origin.map(|x| source_map.get(&x)).flatten() { match origin.and_then(|x| source_map.get(&x)) {
Some(path) => match path { Some(path) => match path {
SpanSource::File(file) => { SpanSource::File(file) => {
full_path.push(Path::new(file)); full_path.push(Path::new(file));

View File

@ -38,7 +38,7 @@ fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
dict.insert("end", Value::int(span.end as i64)); dict.insert("end", Value::int(span.end as i64));
tags.insert_tagged("span", dict.into_tagged_value()); tags.insert_tagged("span", dict.into_tagged_value());
match origin.map(|x| source_map.get(&x)).flatten() { match origin.and_then(|x| source_map.get(&x)) {
Some(SpanSource::File(source)) => { Some(SpanSource::File(source)) => {
tags.insert("origin", Value::string(source)); tags.insert("origin", Value::string(source));
} }

View File

@ -3,7 +3,6 @@
#![feature(generators)] #![feature(generators)]
#![feature(try_trait)] #![feature(try_trait)]
#![feature(bind_by_move_pattern_guards)] #![feature(bind_by_move_pattern_guards)]
#![feature(option_flattening)]
#![feature(specialization)] #![feature(specialization)]
#![feature(proc_macro_hygiene)] #![feature(proc_macro_hygiene)]

View File

@ -1,4 +1,3 @@
#![feature(option_flattening)]
use crossterm::{cursor, terminal, Attribute, RawScreen}; use crossterm::{cursor, terminal, Attribute, RawScreen};
use indexmap::IndexMap; use indexmap::IndexMap;
use nu::{ use nu::{
@ -32,7 +31,7 @@ impl Plugin for BinaryView {
let value_origin = v.origin(); let value_origin = v.origin();
match v.item { match v.item {
Value::Binary(b) => { Value::Binary(b) => {
let source = value_origin.map(|x| call_info.source_map.get(&x)).flatten(); let source = value_origin.and_then(|x| call_info.source_map.get(&x));
let _ = view_binary(&b, source, call_info.args.has("lores")); let _ = view_binary(&b, source, call_info.args.has("lores"));
} }
_ => {} _ => {}

View File

@ -1,5 +1,3 @@
#![feature(option_flattening)]
use crossterm::{cursor, terminal, RawScreen}; use crossterm::{cursor, terminal, RawScreen};
use crossterm::{InputEvent, KeyEvent}; use crossterm::{InputEvent, KeyEvent};
use indexmap::IndexMap; use indexmap::IndexMap;
@ -217,7 +215,7 @@ fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
let value_origin = value.origin(); let value_origin = value.origin();
match value.item { match value.item {
Value::Primitive(Primitive::String(ref s)) => { Value::Primitive(Primitive::String(ref s)) => {
let source = value_origin.map(|x| source_map.get(&x)).flatten(); let source = value_origin.and_then(|x| source_map.get(&x));
if let Some(source) = source { if let Some(source) = source {
let extension: Option<String> = match source { let extension: Option<String> = match source {