7个版本

0.1.6 2023年4月14日
0.1.5 2023年4月14日
0.1.4 2022年12月16日
0.1.3 2022年9月1日

#1053数据结构

Download history · Rust 包仓库 1222/week @ 2024-03-14 · Rust 包仓库 1550/week @ 2024-03-21 · Rust 包仓库 1586/week @ 2024-03-28 · Rust 包仓库 1457/week @ 2024-04-04 · Rust 包仓库 1828/week @ 2024-04-11 · Rust 包仓库 1558/week @ 2024-04-18 · Rust 包仓库 1942/week @ 2024-04-25 · Rust 包仓库 1840/week @ 2024-05-02 · Rust 包仓库 1754/week @ 2024-05-09 · Rust 包仓库 1818/week @ 2024-05-16 · Rust 包仓库 1504/week @ 2024-05-23 · Rust 包仓库 1652/week @ 2024-05-30 · Rust 包仓库 1422/week @ 2024-06-06 · Rust 包仓库 1601/week @ 2024-06-13 · Rust 包仓库 2132/week @ 2024-06-20 · Rust 包仓库 1067/week @ 2024-06-27 · Rust 包仓库

6,446 每月下载量
47 包使用(11 直接使用)

MIT/Apache

9KB
152

Contextual

CI Crate informations License Documentation

一个处理上下文中数据的小包。

use contextual::{WithContext, AsRefWithContext, DisplayWithContext};
use std::fmt;

/// Index of an element in some array.
pub struct Index(usize);

impl<T, C: AsRef<[T]>> AsRefWithContext<T, C> for Index {
  fn as_ref_with<'a>(&'a self, context: &'a C) -> &'a T {
    &context.as_ref()[self.0]
  }
}

impl<'a, C: AsRef<[&'a str]>> DisplayWithContext<C> for Index {
  fn fmt_with(&self, context: &C, f: &mut fmt::Formatter) -> fmt::Result {
    use fmt::Display;
    context.as_ref()[self.0].fmt(f)
  }
}

let i = Index(1);
let context = ["a", "b", "c"];

print!("index: {}", i.with(&context));
assert_eq!(*i.with(&context).as_ref(), "b")

许可协议

根据以下任一许可协议许可:

您可选。

贡献

除非您明确声明,否则根据Apache-2.0许可协议定义的任何有意提交以包含在作品中的贡献,应按上述方式双许可,不附加任何额外条款或条件。

无运行时依赖