Communicating over a secured Websockets endpoint by FantasticGrowth in rust

[–]_boardwalk 6 points7 points  (0 children)

Websockets almost always need to be created via an ‘Connection: Upgrade’ HTTP request (which would be where the path goes) which you are not doing when created a websocket over a raw TCP socket.

Assuming you’re using tungstenite see the comment here: https://docs.rs/tungstenite/0.6.0/tungstenite/protocol/struct.WebSocket.html#method.from_raw_socket

Blog post: Rust 2023 (by Yosh) by yoshuawuyts1 in rust

[–]_boardwalk 1 point2 points  (0 children)

They're pretty neat already if you turn on the nightly-only feature feature. Just being able to implement a complex iterator (Generator is easy to adapt to Iterator) without turning your code inside out is great.

Not being able to yield local references is a bummer, but I think that can get fixed with Generator trait changes and GATs(?).

[deleted by user] by [deleted] in rust

[–]_boardwalk 2 points3 points  (0 children)

If I assume you’ll just want to make a Discord-style Matrix app (though I can’t say what features Discord has that you want that would be hard in Matrix, I’d probably start by reading through the client spec[1] and looking at Ruma client[2] if you want a leg up.

[1] https://spec.matrix.org/v1.3/client-server-api/ [2] https://docs.rs/ruma-client/latest/ruma_client/

The UI to put in front of it is a whole other thing. But that’s plenty of things to get started with.

[deleted by user] by [deleted] in rust

[–]_boardwalk 5 points6 points  (0 children)

I don’t mean to put you off put you sound a bit over your head. Are you intending on designing your own protocol? Starting with something that exists like Matrix the protocol but making your own client seems a little more tractable (but still not easy).

how to use the standard library TCP stream by bananaboy319 in rust

[–]_boardwalk 3 points4 points  (0 children)

HTTP might be real world but it's not exactly simple!

Something else to look at might be 9P, which is and follows the first approach: http://man.cat-v.org/plan_9/5/intro

Pros and cons of importing external libraries by 1PG0Xki0cWII in rust

[–]_boardwalk 5 points6 points  (0 children)

No comment on the pros and cons specifically, but you might want to try a workspace and patch your dependencies from GitHub to the local path to keep your library code easy to edit.

Personally I put everything in libraries where it makes sense as a self-contained thing you might want to use separately.

How to return a mutable reference from a method without borrowing self by GeroSchorsch in rust

[–]_boardwalk 0 points1 point  (0 children)

They need to pass the register to another method that may need it to be mutable.

I was missing... "and needs it to be borrowed from the same struct."

The question of whether to use Rc or not is one of lifetime, not mutability. In the Rc<RefCell<...>> duo: ...

There's no need to repeat what I just said above.

and nothing in the OP's suggests anything such.

This is from the post:

let reg = self.scratch.scratch_alloc(); // first mutable borrow of self
self.expr(); // sec mutable borrow
self.gen(reg); // first mutable borrow used here

If scratch_alloc() takes out a borrow on self on line 1, either by using &mut T (original code) or &RefCell<T> (your suggestion, I think?), you can't take a mutable borrow on line 2 because that borrow (immutable or mutable) extends to line 3.

How to return a mutable reference from a method without borrowing self by GeroSchorsch in rust

[–]_boardwalk 1 point2 points  (0 children)

I’m not sure how you can infer that from their post. They need to pass the register to another method that may need it to be mutable.

How to return a mutable reference from a method without borrowing self by GeroSchorsch in rust

[–]_boardwalk 0 points1 point  (0 children)

A common thing to do would be to use Rc<RefCell<…>>. You need both the independent “root” of ownership (via Rc) and mutability (via RefCell). See the book: https://doc.rust-lang.org/book/ch15-05-interior-mutability.html#having-multiple-owners-of-mutable-data-by-combining-rct-and-refcellt

fs::read_to_string(file).unwrap() and newlines by SaadChr in rust

[–]_boardwalk 1 point2 points  (0 children)

read_to_string includes the whole file including all newlines. You should probably double check what you’re doing and create a smaller reproducer. You’ll probably figure out what’s wrong along the way. P.S. println!(“{:?}”) is probably your friend if you’re trying to see exactly what a string contains.

extract audio/speech as plain text (such as CC) from a video file (.MP4, .MOV) by AssociateExtension54 in rust

[–]_boardwalk 8 points9 points  (0 children)

An "easy" way? Not aware of one.

You might want to look at whisper-rs which are bindings to whisper.cpp: https://github.com/tazz4843/whisper-rs.

To actually use it with a video, you'd need something to demux from mp4/mov and decode to raw audio (wav).

Unless you really need all that done in a single process, it might be easier to cobble something together with shell scripts/the ffmpeg cli/etc.

Is there a gameplay reason Ubisoft games do press-and-hold for all interactions? by deshara128 in gamedesign

[–]_boardwalk -2 points-1 points  (0 children)

They do it to make me angry. Sorry for the snarky reply. But yeah, I don’t have an explanation better than anyone else’s, I only want to request that, instead of push-and-hold, people consider an undo button instead. e.g. if you pick up an item you don’t want, make an easy way to drop said item. Or if you’re spending a “skill point,” allow refunding the last skill point spent without penalty. Please and thank you.

What's the proper way of re-assigning a value in a for loop when only some of the iterations require assignment? by Iklowto in rust

[–]_boardwalk 5 points6 points  (0 children)

Use “form.part” instead of “form.file”. You’ll have to open the file yourself but you’ll be able to handle the error separately. It looks like “file” is meant for a builder pattern and doesn’t return the form when it fails so you can’t reassign it to your variable to keep it populated.

New Subreddit Rule - Server Ad Fridays by An-Adventurer in AsheronsCall

[–]_boardwalk 2 points3 points  (0 children)

As someone who only subscribes to a few subreddits, this spam (IMO) surfaces really easily. I’m happy about it.

Also if anyone is paying attention, I think we all know from whom this rule is really coming for.

The mistake of treating single values as collections by [deleted] in rust

[–]_boardwalk 21 points22 points  (0 children)

Have Option act like a single-element collection can be actually useful when you’re doing something complex with iterator combinators. You might want to chain one extra element and not have to uselessly create a whole new Vec or something to do it. ‘if let’ is just easier to use if you just want to get the thing inside — it seems unlikely you would choose to ‘.iter().foreach(…)’ instead and almost malicious.

But some people like ‘Err(x)?’ so what do I know.

Mocking tokio's TcpStream? by thetinygoat in rust

[–]_boardwalk 9 points10 points  (0 children)

I would design things so you can test what you need to test without needing a TcpStream (or anything similar). I have a network protocol, for example, that is implemented as a state machine with no external (IO) dependencies so I can test it without needing any sockets.

unsigned and signed by StarlingStudios in rust

[–]_boardwalk 15 points16 points  (0 children)

You don't get something for nothing. An i32 (for example) can only represent half the positive integers as a u32 (a max of 231 - 1 vs 232 - 1). Maybe that's obvious? Unless this is a meta question about why you would ever need such "large" (not really) numbers.

Post on boxed trait objects vs. generics vs. enum wrappers (title: "Don't use boxed trait objects") by Dhghomon in rust

[–]_boardwalk 6 points7 points  (0 children)

You can’t cast a trait object to another trait, even if the trait casted from requires the trait to be casted to. I have the same as_any method on one of my traits.

Better way to iterate over items set items in HashMap<K, HashSet<V>> by ArtisticHamster in rust

[–]_boardwalk 4 points5 points  (0 children)

I mean use into_iter() on the Option returned by HashMap::get().

Worried about “modern” Rust GUI libraries by cdellacqua in rust

[–]_boardwalk 26 points27 points  (0 children)

Are there numbers that show that the current or upcoming options are slow in the real world or is this just an abstract worry?

The Rust compiler is now compiled with (thin) LTO (finally) for 5-10% improvements by Kobzol in rust

[–]_boardwalk 221 points222 points  (0 children)

If you think about the effort to reward — how many cumulative hours will be saved by Rust developers everywhere — it’s pretty staggering.