HackerTrans
TopNewTrendsCommentsPastAskShowJobs

fee1-dead

no profile record

Submissions

Item Patterns and Struct Else in Rust

blog.nilstrieb.dev
2 points·by fee1-dead·3 ปีที่แล้ว·0 comments

Apache Statement on White House Open Source Security Summit

cwiki.apache.org
2 points·by fee1-dead·4 ปีที่แล้ว·0 comments

comments

fee1-dead
·5 ปีที่แล้ว·discuss
That's just.. not how Rust works. I assume that after being frustrated by the Rust borrow checker, you chose to use easy to write wrappers like `Arc` and `RefCell`. I think it is something that beginners often do.

I wouldn't rewrite my project to some other language before I know how it is going to look like in the language. I had to be somewhat confident. If you find yourself frustrated by Rust's borrow checker, that tells me that you are not yet ready to port a project to Rust. You don't have the "Rust mindset" yet.
fee1-dead
·5 ปีที่แล้ว·discuss
I suppose the reason is Vec<T> implements `Borrow<[T]>` and [T; N] implements Borrow<[T]> as well. The trait implementation requires these types to have same implementations for all traits including comparisons and hashing.

Returning `false` when types don't match doesn't make sense in Rust since Rust is strongly typed (and not interpreted).

And say if we don't make them compare equal. then vec![1, 2] != [1, 2] but &vec![1, 2] == &[1, 2], which is just too opaque and confusing. This behavior is no fit for a language like Rust.
fee1-dead
·5 ปีที่แล้ว·discuss
> What with this arrows (->) before return types? Seems unnecessary. Couldn't return types be purely positional as in Go?

I guess you could say `->` is too verbose and you can omit it in other languages. Rust has a complex type system and there can be confusing code when you omit `->`.

1. Closure Return Types.

You can define a closure with an explicit return type:

``` let my_closure = |i: u32| -> u64 { i as u64 }; ```

Now how do you omit the arrow here? How do you know `u64` is the return type and not constructing a struct?

2. Parsing stuff

It becomes impossible to parse none-delimited types. Is `fn() fn()` two different types or a function pointer returning a function pointer?

3. Readability

I mean, tokens can be read out loud and omitting it stops making sense.

`fn foo(bar: i32) -> f32` can be read as a "function named 'foo' that takes an argument named bar with type i32 and returns f32". The word returns directly corresponds to the `->` token.

Rust also has the `!` (read: never) type. Poorly formatted code when `->` is omitted is very confusing: `fn a()!` when compared to `fn a()->!`, or just one character generic types: `fn a<T>()T` compared to `fn a<T>()->T`.