wandercn / gostd Goto Github PK
View Code? Open in Web Editor NEWGostd is the golang standard library implementation in rust-lang.
Home Page: https://crates.io/crates/gostd
License: MIT License
Gostd is the golang standard library implementation in rust-lang.
Home Page: https://crates.io/crates/gostd
License: MIT License
挺好的思路,加油!
timestamp_millis 1571893634109 ->RFC3339Nano: 2019-10-24T13:07:14+08:00
正确应该是 2019-10-24T13:07:14.109+08:00
pub fn string(b: &[u8]) -> String
这个函数是不安全的,要么把它定义为 unsafe 的,要么请让它返回一个 Result<String, E>
,比如在那个 &[u8] 不是 utf8 编码时返回错误,Safe Rust 中没有 Go 那种打印出来可能会有乱码的字符串,String 必须是合法的 utf8。
// 据我所知这在 Safe Rust 中是做不到的
b := []byte{255, 255, 255}
fmt.Println(string(b)) // 乱码
原生类型重定义、公共方法首字母大写、用&str做错误返回我也很想吐槽,毕竟这是翻译不是抄一遍,建议还是按照 Rust 而不是 Go 的哲学和规范来吧。
或者至少正确性和安全性上不要打折吧,否则 Go 翻译成 Rust 的意义是什么呢?
use gostd::time;
fn main() {
let year3000 = time::Date(3000, 1, 1, 0, 0, 0, 0, time::UTC.clone());
println!("{}", year3000);
}
m:18446744073709551595
thread 'main' panicked at 'index out of bounds: the len is 13 but the index is 18446744073709551596', /Users/apple/workspace/src/github.com/wandercn/gostd/src/time/mod.rs:2497:20
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
// 这里的m错误导致daysBefore超过索引范围
let mut m = uint!(day / 31);
println!("m:{}",m);
let end = int!(daysBefore[m + 1]);
use gostd::time;
fn main() {
let d = time::Date(2001, 9, 9, 1, 46, 40, 0, time::UTC.clone());
println!("{}", d.Unix());
}
正确的应该是输出是:1000000000 ,这里错误输出了1000000512
gostd version:0.1.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.