[xactor]学习笔记--1

2020-06-11  本文已影响0人  buddyCoder

首先我们先看看cargo.toml文件

[package]
name = "xactor"
version = "0.7.3"
authors = ["sunli <scott_s829@163.com>"]
description = "Xactor is a rust actors framework based on async-std"
edition = "2018"
publish = true
license = "MIT"
documentation = "https://docs.rs/xactor/"
homepage = "https://github.com/sunli829/xactor"
repository = "https://github.com/sunli829/xactor"
keywords = ["actor", "futures", "async", "xactor", "async-std"]
categories = ["network-programming", "asynchronous"]
readme = "README.md"

[dependencies]
futures = "0.3.4"
async-trait = "0.1.24"
async-std = { version = "1.5.0", features = ["attributes"], optional = true }
tokio = { version = "0.2", features = ["rt-threaded", "macros", "blocking", "time"], optional = true }
once_cell = "1.3.1"
anyhow = "1.0.26"
xactor-derive = { path = "xactor-derive", version = "0.7.0"}
fnv = "1.0.6"
slab = "0.4.2"

[workspace]
members = [
    "xactor-derive"
]

[features]
runtime-tokio = ["tokio"]
runtime-async-std = ["async-std"]

default = ["runtime-async-std"]

package 部分

首先感谢 作者 sunli 同学的无私贡献。
然后其他无视 嘿嘿

dependencies 部分

futures

Zero-cost asynchronous programming in Rust
零成本异步编程

async-trait

异步特性

async-std

异步的std

tokio

A runtime for writing reliable, asynchronous, and slim applications with the Rust programming language. 异步运行时

once_cell

OnceCell可以存储任意的非复制类型,最多可以分配给一次,并提供对存储内容的直接访问。

anyhow

这个库提供anyhow::Error,这是一种基于trait对象的错误类型,用于在Rust应用程序中轻松地进行惯用错误处理。

fnv

FNV哈希函数是一个自定义哈希器实现,对于较小的哈希键更有效。
Rust FAQ指出,虽然默认的Hasher实现SipHash在很多情况下都很好,但它明显比其他短键的算法慢,比如当你有一个整数到其他值的映射时。在这种情况下,FNV显然更快。
它的缺点是,它在较大的输入上执行得很差,并且没有提供防止碰撞攻击的保护,在碰撞攻击中,恶意的用户可以设计特定的密钥来减慢碰撞器的速度。因此,配置您的程序以确保您使用的是小散列键,并确保您的程序不会暴露给恶意输入(包括作为一个网络服务器)是很重要的。
Rust编译器本身使用FNV,因为它不担心拒绝服务攻击,并且可以假设它的输入很小——这是FNV的一个完美用例。

slab

无视这个吧。

xactor-derive

我们基本上都了解这些库干啥用的了。

xactor起源

features部分

[features]
runtime-tokio = ["tokio"]
runtime-async-std = ["async-std"]
default = ["runtime-async-std"]

其实就是使用哪个运行时。

基本上就是这样了。那么接着我们开始去看入口文件 /src/lib.rs
只复制粘贴核心代码,其他说明没有复制。

#![allow(clippy::type_complexity)]  //lint的过滤 

mod actor;
mod addr;
mod broker;
mod caller;
mod context;
mod runtime;
mod service;
mod supervisor;

/// Alias of anyhow::Result
pub type Result<T> = anyhow::Result<T>;

/// Alias of anyhow::Error
pub type Error = anyhow::Error;
pub use actor::{Actor, Handler, Message, StreamHandler};
pub use addr::Addr;
pub use broker::Broker;
pub use caller::{Caller, Sender};
pub use context::Context;
pub use runtime::{block_on, sleep, spawn, timeout};
pub use service::{LocalService, Service};
pub use supervisor::Supervisor;
pub use xactor_derive::{main, message};

上面我看到第一行

![allow(clippy::type_complexity)]

真心看不懂,搜了一下。需要先看看 clippy
哦 原来过滤检查语法用的。

然后就是引用 mod 和 pub 出去对应的一些type。

下班 下班 喝酒喝酒

上一篇下一篇

猜你喜欢

热点阅读