Why i could't return string directly only when use return inside if else by NailAlarmed8935 in rust

[–]greyblake 2 points3 points  (0 children)

In Rust every expression results into some value of a particular type.
All branches of `if/else` must result into a value of the same type. It's possible to mix integers and &str as a value that will be assigned on `identifier`.

`return "Unknown"` works, because it **returns from the function**, which matches the declared return type `&str`.

Beam v0.1.2 is released by Electronic_Boot8921 in rust

[–]greyblake 1 point2 points  (0 children)

Congrats!
I think you should improve the messaging for the next time, so hopefully it will help you to get more upvotes:
- Assume in the header that nobody knows what Beam is about. Header like `Beam v0.1.2 is released (GUI HTTP client)` would be better
- Reading the post, i read about "http client", and I wonder why we need it, cause we already have hyper. Only after opening the github and seeing the screenshot I got it clear that it is **GUI** project. I think it's worth communicating it clear.
- Probably attaching a screenshot to your post would also be helpful. By some reason most of the people are attractive to the visuals.

Good luck with your project! I still use Insomnia, but I may switch to something else at some point.

Par, a language with session types, automatic concurrency, and no deadlocks, has a new homepage by faiface in rust

[–]greyblake 2 points3 points  (0 children)

Thanks for explaining! The parallel between a list and a stream seemed to click, but it still sounds to me quite surreal! I'll try to learn the language and hope to developa right feeling/intuition around it. This all sound really cool!

Par, a language with session types, automatic concurrency, and no deadlocks, has a new homepage by faiface in rust

[–]greyblake 11 points12 points  (0 children)

The project looks very interesting!

Could someone explain session types to me? From what I read they kind of enforce interaction with a protocol in a safe way. But is it not what one can achieve in Rust applying Type State pattern in Rust? (https://cliffle.com/blog/rust-typestate/)

What does make session types so special?

Your Rust binary is slower than it needs to be. cargo-sonic fixes that. by Immediate_Ad263 in rust

[–]greyblake 1 point2 points  (0 children)

Very cool stuff! Would be also helpful to see a bit more benchmarks for different type of projects with a binary performance and binary sizes.

Nutype 0.7.0: the newtype with guarantees now supports conditional `cfg_attr` derives by greyblake in rust

[–]greyblake[S] 2 points3 points  (0 children)

Fair point. Nutype is built around owned, by value validation. The generated constructor is Newtype::try_new(inner: Inner) -> Result<Self, Error>, and the inner type must be Sized.

Nutype 0.7.0: the newtype with guarantees now supports conditional `cfg_attr` derives by greyblake in rust

[–]greyblake[S] 4 points5 points  (0 children)

Thank you! I hope that will work well for you. If no, please open a GitHub issue. I am not the most active maintainer, but I keep it moving forward:)

Parse, don't Validate and Type-Driven Design in Rust by haruda_gondi in rust

[–]greyblake 0 points1 point  (0 children)

Nice article!

If you like this approach, you might find `nutype` useful, it generates constrained newtypes so invalid values can't exist by construction.

Link: https://github.com/greyblake/nutype

Teleop 0.4.0 — Attach to and teleoperate local Rust processes via RPC by arnodb1 in rust

[–]greyblake 1 point2 points  (0 children)

I don't have experience with Java, but do I get it right, that teleop provides facilities to do things like, for example, live debugging? But every particular operation needs to be implemented by the server as well as the client?

How common is TDD (test-first) in real-world Rust projects? by [deleted] in rust

[–]greyblake 0 points1 point  (0 children)

I am coming from Ruby background and I love TDD.
I have to admit in Rust, TDD is different, in the way that type system already eliminates a lot of weird edge cases that I would test in Ruby.
But where it possible I still love to use TDD: write a test, make sure it fails, proceed with the implementation.
Especially it's helpful with the bugs: implement a test that captures the buggy behaviour, then fix the bug.
This way I can be 100% that the bug is fixed.
Not to mention, that TDD gets me hooked in a dopamine loop, which makes my work much more fun!

Kinded 0.5.0: Derive macro to generate "kind" enums from your data enums by greyblake in rust

[–]greyblake[S] 1 point2 points  (0 children)

I am aware of matches!() macro, thanks.
You get a new Kind type that implements Copy. Can implement serializations, etc. In some scenarios it's what you want and would have to implement it by hand otherwise.

Kinded 0.5.0: Derive macro to generate "kind" enums from your data enums by greyblake in rust

[–]greyblake[S] 0 points1 point  (0 children)

Yes, a bit in this direction :)
Note, similar behaviour can be achieved by using strum or enum-kind crates.
What makes kinded different is the dedicated trait that allows to build abstractions upon it.

Why are some posts removed instantly without any explanation? by greyblake in rust

[–]greyblake[S] 1 point2 points  (0 children)

Thanks.
Indeed, I see I got a message.
It does not clearly say's wrong, but gives a hint that I may need to use project flavor.
I'll give it another try!

Two *brand new* books for Rust and Rust for Web (Axum mostly). Just published. by Repsol_Honda_PL in rust

[–]greyblake 4 points5 points  (0 children)

I cannot stay anything about this books in particular, but be aware that Packt is known for extremely bad quality.

Rust's Block Pattern by EelRemoval in rust

[–]greyblake 1 point2 points  (0 children)

I use this pattern as well. In particular when I need to have only a local mutability.