4个版本

使用旧的Rust 2015

0.0.4 2015年8月22日
0.0.3 2015年5月20日
0.0.2 2015年5月18日
0.0.1 2015年4月25日

#22 in #frp

MIT 许可证

65KB
1.5K SLoC

并发函数响应式编程(针对Rust)

Rust中实现的并发FRP。

Build Status

文档

这基本上是将Elm移植过来。如果你不熟悉Elm或Evan Czaplicki的并发FRP的设计,你应该阅读Elm: Concurrent FRP for Functional GUIs或观看他在2014年StrangeLoop的演讲

其他选项(我知道的)

待办事项

  • 文档/日志
  • 实现Display/Debug
  • 尝试消除约束

lib.rs:

并发函数响应式编程

高度受Elm的影响 - 提供了一个描述和执行并发数据流过程的框架。

示例

use std::default::*;
use std::sync::mpsc::*;
use cfrp::*;

// create some channels for communicating with the topology
let (in_tx, in_rx) = channel();

// Topologies are statically defined, run-once structures.  Due to how
// concurrency is handled, changes to the graph structure can cause
// inconsistencies in the data processing
// 
spawn_topology(Default::default(), |t| {

    // Create a listener on `in_rx` with initial value `0`.  Messages 
    // received on the channel will be sent to any nodes subscribed to `input`
    let input = t.listen(0usize, in_rx).add_to(t);

    // Basic map operation.  Since this is expected to be a pure function, 
    // it will only be evaluated when the value of `input` changes
    let plus_one = input.lift(|i| { i + 1 }).add_to(t);

    // The return value of `add` / `add_to` implements `clone`, and can be used to
    // 'fan-out' data
    let plus_two = plus_one.clone().lift(|i| { i + 2 });

    // We can combine signals too.  Since it's possible to receive input on one
    // side but not the other, `lift2` wraps data in a `Value<T>` which is 
    // either `Value::Changed(T)` or `Value::Unchanged(T)`.  Like `lift`, 
    // this function is only called when needed
    let combined = plus_one.lift2(plus_two, |i, j| { *i + *j });

    // `fold` allows us to track state across events.  
    let accumulated = combined.fold(0, |sum, i| { sum + i });

    // Make sure to add transformations to the topology with `add` / `add_to`
    // I it's not added it won't be run...
    t.add(accumulated);
});

in_tx.send(1usize).unwrap();

依赖关系

~1.5MB
~23K SLoC