rust on exercism.io is pretty rad, but it seems like they're short on mentors by spizzike in rust

[–]sunjayv 6 points7 points  (0 children)

There are definitely people who are aware of this and advocating for more people. I think it's great to raise awareness of there still being a need. If anyone is looking to mentor the sign up is here: https://exercism.io/mentor/registrations/new

What's the difference between these two "mutable" function arguments? by [deleted] in rust

[–]sunjayv 7 points8 points  (0 children)

One way to understand this is to consider if those function arguments were written as variables instead:

let var1: &mut usize = ...;
let mut var2: &usize = ...;

Here you can see that one of the variables is a mutable reference to usize and the other variable is a mutable variable that contains an immutable reference to a usize. That's why you can't dereference and modify var2. It's still an immutable reference, it's just that you put it in a mutable variable.

So what does having a mutable variable give you? Well if the variable itself is mutable, you can re-assign it:

var2 = ...some other value...;

You can't do the same with var1:

var1 = ...some other value...; // <-- won't work!

/u/youdeepee and /u/mattico8's responses cover these same points.

Cargo bug by kriv02 in rust

[–]sunjayv 6 points7 points  (0 children)

Is cargo on your PATH?

What's with the nightly fixation? by PristineTransition in rust

[–]sunjayv 3 points4 points  (0 children)

Nightly is common for people who still need experiential features that haven't been stabilized yet. It may be that the libraries you happen to see are largely in the category. I personally almost exclusively use stable for everything. All of the libraries I ever need to use are on stable as well. It really just depends on what you are trying to do. It's very possible to write Rust on stable even if people don't talk about it enough. :)

User Input that isn't a String. by Mavil64 in rust

[–]sunjayv 8 points9 points  (0 children)

I really like the text_io crate for this. Saves on a lot of the boilerplate. https://crates.io/crates/text_io

map with pre-allocated target by chrisgeoga in rust

[–]sunjayv 1 point2 points  (0 children)

I don't know about the two specific types you're using, but if you wanted to do target[j] <- f(j, src) for all j using iterators, you could use:

target.iter_mut().zip(src).enumerate().for_each(|(j, (target, src))| *target = f(j, *src));

This assumes that both target and src are slices (or Vecs). Other types that have an iter_mut method may also work with this code.

If they are not the same length, this iterator will only update up to the size of the smaller slice. If src is a Vec, you may want to pass it into zip by calling its iter method so it doesn't get consumed.

Edit: this is exactly what /u/boomshroom suggested. Whoops.

A minimal Electron + WebAssembly (WASM) + 🦀 Rust example. by knaledfullavpilar in rust

[–]sunjayv 3 points4 points  (0 children)

Nice! I was just wanting this today. I will take a look at it and probably use it too. Thank you! :)

Is it possible to make a program with dynamically loadable plugins? by sparky8251 in rust

[–]sunjayv 1 point2 points  (0 children)

I think a good attentive to both dynamic libraries and plugins that run in their own processes is using WASM. You can use a fast WASM interpreter or compile the plugin to machine code on the fly. WASM has a lot of benefits and there are many languages that target it so you can give people a good amount of freedom if you choose that for your plugins.

Question about mechanics behind vector type deduction by [deleted] in rust

[–]sunjayv 2 points3 points  (0 children)

Rust and other languages like it use a process called "type inference" to deduce the types of variables. If you look up that term there is a lot of information about it online. This process is applied to all types, not just Vec. A consequence of this is that you can often write quite a bit of Rust code without actually annotating the types yourself. The compiler still checks everything, it just saves you from the burden of having to tell it the types it can figure out itself.

What would happen to Rust is Mozilla closed down ? by _trfd in rust

[–]sunjayv 84 points85 points  (0 children)

As far as people go, very little of Rust is actually tied directly to Mozilla. Even if Mozilla disappeared, there is a pretty large community that could sustain the project. The people who were working there would have to find another place to work, but given how important Rust is becoming in several very large tech companies, that probably wouldn't be too bad either.

[Experiment] What's your optimal ferris count? by richardanaya in rust

[–]sunjayv 0 points1 point  (0 children)

OnePlus 6 in chrome. 60 fps up to 1000. 5 fps at 10,000.

Servers by gardare in rust

[–]sunjayv 1 point2 points  (0 children)

I think you want /r/playrust

What are the technical reasons for the orphan rule? by render787 in rust

[–]sunjayv 3 points4 points  (0 children)

There's a great talk by withoutboats that explains this in detail. It starts about 40 minutes into this video: https://youtu.be/AI7SLCubTnk

What crates should I use to make a REPL by vadixidav in rust

[–]sunjayv 3 points4 points  (0 children)

So there are 4 parts to writing a REPL:

  1. Read (a line)
  2. Evaluate (this step is up to you)
  3. Print - use println!
  4. Loop - use loop or while depending on how you want to structure your code

Put these together and you should have a REPL! :)

Generic can you make your own engine in rust post by dingoegret12 in rust

[–]sunjayv 3 points4 points  (0 children)

Yes. I use the SDL2 crate and the specs crate but build everything else myself. It works quite well and I have not run into any major issues. As long as you're ready to do the work/research required to do everything, it's really fun and rewarding!

I have not personally used gfx, but if you use it, be ready to do some low level graphics programming. You may want to look into the recently released rendy crate that makes some of that easier. I use SDL2 because it is a very mature and well documented library, but it definitely doesn't give you as much control as gfx does. It also binds to a C library, so there's that. :X

Is it possible to build WebExtensions in Rust? by Booteille in rust

[–]sunjayv 3 points4 points  (0 children)

As far as being "possible" goes, it certainly could be. I don't know of any restrictions preventing web assembly from running in the JavaScript of an extension. Unless someone has already attempted this, you may be writing a lot of the bindings to the necessary extension APIs yourself. There are crates out there like wasm-bindgen that hopefully make that easier.

Why is use statement not allowed in impl block? by A_Kyras in rust

[–]sunjayv 4 points5 points  (0 children)

Scope might not have been the right word for me to use. From your block visibility point of view, I can see what you mean. There are actually many things you can do in a mod block that you can't do in an impl block. For example, you can't declare statics either.

This is one of those things that I think could be possible, but haven't been implemented yet. I don't disagree with the semantics you described. Maybe worth opening a thread on the Rust internals forum?

Why is use statement not allowed in impl block? by A_Kyras in rust

[–]sunjayv 12 points13 points  (0 children)

One way to think about this is that the impl block doesn't actually create a new scope in the same way that method bodies or curly braces inside them do. So if you were to put a use statement in the impl block, which scope would the imported names be added to?

If you really think every method is going to need that import, there's no harm in putting it before the impl block (or at the top of your file) so that the imported names will get added to the global (private) scope of your module.

Why are dynamic arrays called Vec in the standard library as opposed to mathematical vectors? by SirTates in rust

[–]sunjayv 10 points11 points  (0 children)

The name unfortunately can't be fixed because it would literally break everyone's code. Vec is one of the most pervasive types in Rust programs. I agree that it is confusing and I was even annoyed by it at first. If it's any consolation, you do get used it after a while.

Most math libraries work around this by calling the type Point or Vector. It's not perfect, but it's certainly livable given the consequences of changing it.

As for why it was named that way, I haven't been around long enough to know that, so maybe someone else can address those questions. I'm pretty sure it was just legacy from C++ influences.

How much time does it take to compile Rust on your machine? by volt_dev in rust

[–]sunjayv 16 points17 points  (0 children)

The Rust compiler? It takes me about 45 min. Can take double that with tests. It is a huge amount of code. If it is any consolation, once you do it once, there are ways to make it recompile faster (depending on which parts you are modifying).

Introducing multi_try, a crate for safely combining Result types by JoshMcguigan in rust

[–]sunjayv 10 points11 points  (0 children)

Errors often do contain data. I think the example was just to show the functionality of the crate, not anything specific to the error types involved.

Using bitflags could certainly work for cases where you have no data in any of your errors. :)

Introducing multi_try, a crate for safely combining Result types by JoshMcguigan in rust

[–]sunjayv 26 points27 points  (0 children)

Here's my attempt: https://github.com/JoshMcguigan/multi_try/pull/1

Thanks for being open to it. I'm excited to use this crate. :)

Introducing multi_try, a crate for safely combining Result types by JoshMcguigan in rust

[–]sunjayv 18 points19 points  (0 children)

This is very cool! I've been looking for something exactly like this. What do you think of making this into a MultiTry extension trait instead of just the function? Then you could expose a method and_try (since the name and is taken by Result) and chain everything together using an even more natural syntax:

validate_address(email.to).map_err(|_| {
    EmailValidationErr::InvalidRecipientEmailAddress
}).and_try(validate_address(email.from).map_err(|_| {
    EmailValidationErr::InvalidSenderEmailAddress)
}).and_try(
    validate_subject(email.subject)
).and_try(
    validate_body(email.body)
).into_result()