< 返回版块

挺肥 发表于 2020-12-02 22:21

GATs(generic_associated_types)通过features fate可以在 nightly 中使用

例子如下:

#![feature(generic_associated_types)]

trait Monad /* : Applicative (for pure/return, doesn't matter for this example) */ {
    // Self is like the "f a" in haskell

    /// extract the "a" from "f a"
    type Unplug;

    /// exchange the "a" in "f a" in the type of Self with B
    type Plug<B>: Monad;

    fn bind<B, F>(self, f: F) -> Self::Plug<B>
    where
        F: Fn(Self::Unplug) -> Self::Plug<B>;
}

impl<A> Monad for Option<A> {
    type Unplug = A;
    type Plug<B> = Option<B>;
    fn bind<B, F>(self, f: F) -> Option<B>
    where
        F: Fn(A) -> Option<B>,
    {
        self.and_then(f)
    }
}

fn main() {
    let x = Some(1).bind(|x| Some(x * 2));
    println!("{:?}", x);
}

https://www.reddit.com/r/rust/comments/k4vzvp/gats_on_nightly/

cargo-aoc: Advent of Code 的命令行工具

Advent of Code 是一个解谜网站。Cargo-aoc提供了一个命令行工具来方便你玩aoc。

https://github.com/gobanos/cargo-aoc

Sensei:快速打开 crate 文档

例如:

sensei serde

就可以打开 https://docs.rs/serde/

https://crates.io/crates/sensei


From 日报小组 @挺肥

社区学习交流平台订阅:

评论区

写评论

还没有评论

1 共 0 条评论, 1 页