当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust Bound.map用法及代码示例


本文简要介绍rust语言中 std::ops::Bound.map 的用法。

用法

pub fn map<U, F>(self, f: F) -> Bound<U> where    F: FnOnce(T) -> U,

通过将函数应用于包含的值(包括 IncludedExcluded ),将 Bound<T> 映射到 Bound<U>,返回相同类型的 Bound

例子

#![feature(bound_map)]
use std::ops::Bound::*;

let bound_string = Included("Hello, World!");

assert_eq!(bound_string.map(|s| s.len()), Included(13));
#![feature(bound_map)]
use std::ops::Bound;
use Bound::*;

let unbounded_string: Bound<String> = Unbounded;

assert_eq!(unbounded_string.map(|s| s.len()), Unbounded);

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 std::ops::Bound.map。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。