前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Rust日报】 2020-01-11 postgres-query, 新的分词器库tokenizers

【Rust日报】 2020-01-11 postgres-query, 新的分词器库tokenizers

作者头像
MikeLoveRust
发布2020-02-12 15:05:41
5720
发布2020-02-12 15:05:41
举报

postgres-query

这个crate提供了方便的宏和trait,可帮助编写SQL查询并将其结果收集到静态类型的结构中。

示例代码:

代码语言:javascript
复制
// Connect to the database
let client: Client = connect(/* ... */);

// Construct the query
let query = query!(
    "SELECT name, age FROM people WHERE age >= $min_age",
    min_age = 18
);

// Define the structure of the data returned from the query
#[derive(FromSqlRow)]
struct Person {
    age: i32,
    name: String,
}

// Execute the query
let people: Vec<Person> = query.fetch(&client).await?;

// Use the results
for person in people {
    println!("{} is {} years young", person.name, person.age);
}

Github

新的分词器库tokenizers

分词器的核心是用Rust编写的。提供当今最常用的分词器的实现,重点是性能和多功能性。

示例代码

代码语言:javascript
复制
use tokenizers::tokenizer::{Result, Tokenizer, EncodeInput};
use tokenizers::models::bpe::BPE;

fn main() -> Result<()> {
let bpe_builder = BPE::from_files("./path/to/vocab.json", "./path/to/merges.txt")?;
let bpe = bpe_builder
		.dropout(0.1)
		.unk_token("[UNK]".into())
		.build()?;

let mut tokenizer = Tokenizer::new(Box::new(bpe));

let encoding = tokenizer.encode(EncodeInput::Single("Hey there!".into()))?;
println!("{:?}", encoding.get_tokens());

Ok(())
}

Github

一个PR,在Rust 1.40中删除对proc-macro-hack的依赖

使用Rust 1.40时,类似函数的宏可以生成macro_rules!,因此,删除对proc-macro-hack的依赖非常容易。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-01-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Rust语言学习交流 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • postgres-query
  • 新的分词器库tokenizers
  • 一个PR,在Rust 1.40中删除对proc-macro-hack的依赖
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档