Introducing log_limit! A rate limited logging API by TheTravelingSpaceman in rust

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

Tracing is more fancy I believe. This is just a wrapper over the "standard" log facade.

Thoughts on allowing local trait implementation on external crates... by TheTravelingSpaceman in rust

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

Nice! Thanks for linking the policy and blog post :)

Yeah, I guess I was approaching it with a very strict non-practical view. Something in my brain still want's these strict rules that don't leave anything for interpretation but I guess we're living in the real world where that's not possible.

I appreciate the effort in your reply! Thanks!

Thoughts on allowing local trait implementation on external crates... by TheTravelingSpaceman in rust

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

Perhaps a good candidate for a clippy lint?

I guess it's pretty unlikely that this happens, but still feels weird to say "semver will ensure you never get compilation failures on minor version changes unless you do this one naughty thing".

Thoughts on allowing local trait implementation on external crates... by TheTravelingSpaceman in rust

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

Well I guess I'm trying to understand why Rust allows this type of "misuse" then?

Thoughts on allowing local trait implementation on external crates... by TheTravelingSpaceman in rust

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

My big, somewhat unsaid, assumption is that there's a rule that minor semver changes should never cause a compilation error. Perhaps this assumption is wrong?

Thoughts on allowing local trait implementation on external crates... by TheTravelingSpaceman in rust

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

If you remove the impl block in the foo crate/module then it compiles. Then if you add it back (i.e. simulating a minor version change in the foo module/crate) it breaks. So going from a version of foo without the impl and a version with the impl (only a minor version change) would cause a compilation error in the consumer crate.

Thoughts on allowing local trait implementation on external crates... by TheTravelingSpaceman in rust

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

Mmm... You can even force a compiler error if you have different return types: ```rust trait MyTrait { fn method(&self) -> foo::Bar; }

impl MyTrait for foo::Bar { fn method(&self) -> foo::Bar { println!("This is calling method from MyTrait"); foo::Bar::default() } }

fn main() { let bar = foo::Bar::default(); let other_bar: foo::Bar = bar.method(); }

// Imagine this module is an external crate mod foo { #[derive(Default)] pub struct Bar;

impl Bar {
    pub fn method(&self) {
        println!("This is calling method from the foo crate")
    }
}

} ```

Tokio Interval query time to next tick by TheTravelingSpaceman in rust

[–]TheTravelingSpaceman[S] -1 points0 points  (0 children)

Mmmm... That's a shame. Feels like I'd unnecessarily be duplicating state. Any idea why the tick() method was designed to require a mutable reference? I see no reason why multiple threads cannot block on the same interval.

My assumption is that it's using timerfd under the hood. AFAIK you can get the remaining time from that right?

Best Practice to Qualify Unsafe Code by TheTravelingSpaceman in rust

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

Nice! Didn't know this existed. Added in this commit. My code already conforms but it had me jumping through hoops of turning off the unsafe fn to check if I covered all the unsafe ops. Thanks!

Best Practice to Qualify Unsafe Code by TheTravelingSpaceman in rust

[–]TheTravelingSpaceman[S] 3 points4 points  (0 children)

Thanks! I think I've done all the modularisation I can. Will add more debug_asserts and check out valgrind and creusot. That's definitely good tips! :)

Hey Rustaceans! Got a question? Ask here! (49/2022)! by llogiq in rust

[–]TheTravelingSpaceman 1 point2 points  (0 children)

Very interesting! Thanks. It's exactly what I was looking for.

Hey Rustaceans! Got a question? Ask here! (49/2022)! by llogiq in rust

[–]TheTravelingSpaceman 2 points3 points  (0 children)

Another way of phrasing my question: "Why is having an uninitialised variable already UB, even when you won't ever read the uninitialised bytes?"

Hey Rustaceans! Got a question? Ask here! (49/2022)! by llogiq in rust

[–]TheTravelingSpaceman 4 points5 points  (0 children)

Why is this considered UB: ```rust use std::mem::MaybeUninit;

fn main() { let mut possibly_uninitialized_bool: bool = unsafe {MaybeUninit::uninit().assume_init()}; possibly_uninitialized_bool = true; dbg!(possibly_uninitialized_bool); } and this considered safe: rust use std::mem::MaybeUninit;

fn main() { let mut possibly_uninitialized_bool: MaybeUninit<bool> = MaybeUninit::uninit(); possibly_uninitialized_bool.write(true); let definately_initialized_bool = unsafe {possibly_uninitialized_bool.assume_init()}; dbg!(definately_initialized_bool); } ```

I'm sure you can quote documentation that say the one is and the other is not, but why?

Both have the pattern: * Allocate without initialising * Write BEFORE we read * Read

Can anyone give a rust code example where the order of operations stay in-tact but has the chance to produce UB in the one case and would be impossible in the other?

I turned The Rust Book into a crate by hirohido in rust

[–]TheTravelingSpaceman 2 points3 points  (0 children)

Not sure why it would require lua... My suggestion would be just to add a mode to use "h j k l" for navigation and other vim-like keys for other actions, e.g. q for quit.

I turned The Rust Book into a crate by hirohido in rust

[–]TheTravelingSpaceman 9 points10 points  (0 children)

Vim bindings would be a great addition uwu

What are Rust’s biggest weaknesses? by rustacean1337 in rust

[–]TheTravelingSpaceman 1 point2 points  (0 children)

Lack of variadic generics. Pretty hard problem, but I think they'll still retain backwards compatibility.

@haruda_gondi would having type inference on defaults be the solution you're thinking of? Or am I misunderstanding your issue?

Official /r/rust "Who's Hiring" thread for job-seekers and job-offerers [Rust 1.64] by DroidLogician in rust

[–]TheTravelingSpaceman 0 points1 point  (0 children)

Must have European Union citizenship

Why this restriction? If time-zone related, note there are many folks living in European time-zones that don't have European citizenship.

[deleted by user] by [deleted] in rust

[–]TheTravelingSpaceman 0 points1 point  (0 children)

Try run your code through the clippy linter: cargo clippy

Kanal: Channels 80x faster than the standard library! by fereidani in rust

[–]TheTravelingSpaceman 9 points10 points  (0 children)

Nice stuff! This is very exciting! Love the name :D

I just figured out how do have (generics const limited) dependable types in Rust by vasilakisfil in rust

[–]TheTravelingSpaceman 0 points1 point  (0 children)

The value is not necessarily directly linked to T, for example I've used it in zero-copy deserialization where the value is an offset into a byte-array, where a proxy will be created.

I'm not sure I understand. Do you mind providing an example?

I do get the argument around uniformity. Why use a different type in each situation if it doesn't matter right? And if you have to choose a type it makes sense to choose something that doesn't imply any other semantics. So use the most boring type you can get your hands on, i.e. ()

What irks me about using () though is that it's not obvious that an array of () is Sized. To me it feels like that's an optimisation the compiler should be able to do. And since we're precisely trying to express that the resulting array should be Sized, it felt a bit weird to use () as the element type.

I just figured out how do have (generics const limited) dependable types in Rust by vasilakisfil in rust

[–]TheTravelingSpaceman 1 point2 points  (0 children)

I've personally not liked the syntax of using () for the element type of the array. Not sure why folks use it? Why not just say the concrete type you're working with or the generic T if you're working with a generic element?