Coder Social home page Coder Social logo

gostd's Issues

"fn string" is unsafe

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 的意义是什么呢?

absDate 函数错误

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]);

time.unix 时间戳不对

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.