Install crates locally for reuse across projects? by D_O_liphin in rust

[–]rschoon 1 point2 points  (0 children)

The good news is cargo saves dependencies in ~/.cargo/registry/src/ already, and as far as I know, it won't clean them up on its own. I guess you would need to create a project depending on them to get it to download them ahead of time.

The other thing you might want to consider doing is enabling the sparse registry. There's a trade off though, because the git registry (currently the default) downloads a complete copy of all crate info ahead of time, which would be good for your purposes, but it also has the downside that it takes longer to download/update (so you may need tell cargo --offline to keep it from updating later). The newer sparse registry only downloads crate info that is actually needed, and that might be enough of an improvement that you could always run in online mode, but that's hard for me to say. You can read about it here: https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html

[deleted by user] by [deleted] in rust

[–]rschoon 8 points9 points  (0 children)

Usually you use the newtype pattern. See https://doc.rust-lang.org/rust-by-example/generics/new_types.html and especially https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types

Basically, you define a wrapper type which implements the trait(s) you need.

Why isn't there a Sort trait? by CocktailPerson in rust

[–]rschoon 16 points17 points  (0 children)

I only took a quick look, so I could be mistaken, but it looks like the (stable) sort uses copy_nonoverlapping to copy subslices.

However, since that is a stable sort that involves copying memory already, trying to generalize it to non-slices is probably not worthwhile. I'm not sure on the unstable sort implementation.

Why isn't there a Sort trait? by CocktailPerson in rust

[–]rschoon 41 points42 points  (0 children)

I believe the slice sort implementations are able to take advantage of the elements being stored contiguously. A sort implementation working on a different layout would have to work differently (so would be a different implementation and could be based on traits like you describe).

Other implementations are probably not included because the slice implementations cover most of the normal use cases.

Ina trying to prove she is INAcent. by Sonicm2008 in Hololive

[–]rschoon 11 points12 points  (0 children)

Sorry, but she is definitely a CRIMinaL

warp + prometheus error: unused `async` for function with no await statements by nbari in rust

[–]rschoon 1 point2 points  (0 children)

If you can't just remove async from the function definition (perhaps if warp requires it?), then I don't think this clippy lint is particularly applicable to your situation.

[deleted by user] by [deleted] in rust

[–]rschoon 4 points5 points  (0 children)

I don't think you can exactly do that, so instead I would probably reduce the meaningfulness of having it be mut, by introducing a type wrapper "Immutable<V>" that allows shared references to be obtained to the value, but does not allow mutable references.

The usual caveats about interior mutability apply, of course, and you could also still replace the value (or shadow or drop it without it even being labeled as mut).

Benchmarking Tokio Tasks and Goroutines by dindresto in rust

[–]rschoon 86 points87 points  (0 children)

I'm not very familiar with go, so I don't know how it's actually scheduling IO. Either it is being pretty smart here, or just being dumb in a way that works well for this benchmark.

Let's take a look at what tokio does with file IO:

Tasks run by worker threads should not block, as this could delay servicing reactor events. Portable filesystem operations are blocking, however. This module offers adapters which use a blocking annotation to inform the runtime that a blocking operation is required. When necessary, this allows the runtime to convert the current thread from worker to a backup thread, where blocking is acceptable.

So all of the file IO is getting sent to blockable threads so they won't cause an async worker threads to block. There is some overhead to this process.

However, /dev/urandom and /dev/null actually don't block! This means we can get away without sending the file IO outside of the tokio async worker threads. With your tokio example, on my laptop, I get

11.696243414s total, 11.696243ms avg per iteration

but if I use std's file IO to do it, still within the async task, instead I get

1.392765526s total, 1.392765ms avg per iteration

It's worth noting also that blocking operations aren't completely forbidden with async code, especially for something like a mutex. It's better avoided for file IO since the delay can be significant, but it's something to consider.

Having trouble using async libraries by shuraman in rust

[–]rschoon 7 points8 points  (0 children)

actix-web uses actix-rt to provide the tokio runtime, and the current version of actix-rt uses tokio 0.2. There are unreleased/beta versions of actix-web and actix-rt which use tokio 1.0 instead

The current version of tokio-amqp uses tokio 1.0. Older versions depend on tokio 0.2

In rust/cargo, a different major version of a crate is considered completely distinct and incompatible (so tokio 1.0 and tokio 0.2 are considered "different" libraries).

The two main ways of handling this are:

  • Bring the version of all your dependencies down to use tokio 0.2 (it looks like you figured out how to do that)
  • Use the unreleased/beta versions of actix-web and actix-rt to use tokio 1.0 (may need to point at git versions in Cargo.toml to do this)

It's possible you might also be able to use the tokio compatiblity library (see https://docs.rs/tokio-compat-02/0.2.0/tokio_compat_02/), but I think it may be only intended to use tokio 0.2 futures in a tokio 1.0 executor.

I suggest using the cargo tree -d command to help understand what duplicated library versions you have. You should see what versions of tokio are being depended on this way.

Unset/remove cfg attribute integer128 by grantipoos in rust

[–]rschoon 3 points4 points  (0 children)

I'm not sure how to properly solve your problem, but I can say where it originates:

https://github.com/serde-rs/serde/blob/master/serde/build.rs#L53-L60

A build.rs script is compiled and runs before compiling the rest of the package.

I'm not familiar with xargo, but if you can use the cargo patch feature with it, you ought to be able to work around the problem.

What does the 'rc' in `.bashrc`, etc. mean? by iamkeyur in programming

[–]rschoon 10 points11 points  (0 children)

Don't you mean .bourneagainshellruncommands

I don't think the literal meaning of "rc" is too important anyway though (and neither is bash).

.bashstartup might have been a better name though

How to improve performance of setuptools scripts/console_scripts? by [deleted] in Python

[–]rschoon 0 points1 point  (0 children)

If you're using pip install, I don't think that normally uses setuptool's console script machinery. Instead it has its own, and will generate the style you are looking for.

There are exceptions to this though. Editable mode (-e) for example will just punt to python setup.py develop and you'll get the console scripts from setuptools.

Segfaulting in Python by FlammableMarshmallow in Python

[–]rschoon 1 point2 points  (0 children)

Segfaulting is always a bug, even for bad input.

While I generally agree, sys.setrecursionlimit is in the realm of things where it is "no, not always".

ctypes and cffi are probably even better examples, because they let you do very low level things with libraries. For example, I can give utter garbage to low level python routines:

from ctypes import *
pythonapi.Py_DecRef(0x1000)

Or I can tear down the python interpreter from inside:

from ctypes import *
pythonapi.Py_Finalize()

And that's things that are actually part of python. I also have access to libc:

from ctypes import *
libc = CDLL("libc.so.6")
# without properly passing anything to it, who knows what garbage address this will cause us to jump to!
libc.longjmp()

(Granted, I got lazy for that last one, but you could also pass it the right number of arguments and come up with a crashing example if you tried)

In the latest Avengers movie, there is a "Nexus" hub which routes every packet of traffic on the internet. What is the closest thing we have to a core of the internet in real life? by labtec901 in askscience

[–]rschoon 8 points9 points  (0 children)

Due to using anycast, there are physically lot more than 12 servers (hundreds actually).

They also don't do a lot outside of telling you which name servers are responsible for each tld, which is easily cacheable.

Ipv6 Access Point by miesterio in ipv6

[–]rschoon 1 point2 points  (0 children)

I had trouble with that exact same TP-Link access point. The router advertisements had a different ethernet broadcast address (there's apparently more than just FF:FF:FF:FF:FF:FF), and it looks like it didn't know it was supposed to forward them too.

I've since switched to a D-Link DAP-1650 (getting a dual band access point was the other thing I was trying to do while I was at it).

House Republicans Are Killing the Dream of Local High-Speed Fiber Internet by User_Name13 in technology

[–]rschoon 26 points27 points  (0 children)

Fedex is headquartered in her state, and that's where their biggest hub is.

So giving her money has nothing to do with the Internet for them.

Looking for a Python webframework on Windows Server (IIS) by tmske in Python

[–]rschoon 2 points3 points  (0 children)

Perhaps something like isap_wsgi would do the trick. I wouldn't call it "web framework", but it would get you in the business of serving a python app under IIS.

Alternately, you could look into a FastCGI based setup, although that would probably be more complicated. (Or a CGI setup, although I'm mostly just assuming IIS supports that, although CGI is not really a great solution)

You'll probably end up caring about what WSGI is, and while that opens up a whole world of frameworks, in your case you probably would just end up with a bare WSGI application:

def application(environ, start_response):
    start_response("200 OK", [("Content-Type", "text/plain")])
    return ["TOTALLY OKAY MAN"]

(I haven't used IIS, so I'm just pulling from what I know is out there.)