Note: both code fragments and links contain things like &
Yes, I know. lemmy mangles stuff like ampersand and less than even inside code blocks. I noted this in an edit for the main post and included a playground link as well.
https://github.com/KerfuffleV2 — various random open source projects.
Note: both code fragments and links contain things like &
Yes, I know. lemmy mangles stuff like ampersand and less than even inside code blocks. I noted this in an edit for the main post and included a playground link as well.
Thanks for the reply. Unfortunately, I could just use Any
for that since Vec
is 'static
as long as the items are (and I don’t think you could use anyvec
if the tiems weren’t static).
I asked in the Rust Discord channels and it seems like my approach is fine. Even the mutable version is okay and doesn’t need to be unsafe if it returns the reference with self
’s lifetime.
The more I think about it, the more I’m convinced the immutable slice version is safe. I’m pretty sure the mutable version in the playground is also safe because you can’t turn it into a mutable reference without consuming it and it requires a mutable reference to build.
The mutable version is pretty inconvenient to actually use if you want to store the AnySliceMut
and pass it to other functions. The other function would have to reconstruct it and pass it back once it was done with the mutable reference. But what if:
// ^ impl AnySliceMut
pub unsafe fn as_slice_mut(&mut self) -> Option<&'a mut [T]> {
if TypeId::of::() != self.tid {
return None;
}
Some(unsafe { std::slice::from_raw_parts_mut(self.ptr as *mut T, self.len) })
}
Obviously it’s possible to abuse but if I just do something like pass it to a function that takes a mut ref and that function doesn’t do anything weird like save the reference is this okay? MIRI is apparently okay with it: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=149ad441a1c66b3f1fd7f2107acbeccf
Would a link to crates.io be enough here?
I’d tend to say: probably not. It’s not that people don’t know that crates.io exists, right? So that’s not changing anything.
or want to find a new crate for some topic I go to lib.rs
And lib.rs will suppress the visibility of crates it thinks are “bad” and you’d never even know the crate existed to go look at the objective data on crates.io. Or let’s say a result comes up but it’s just an empty page with a link to crates.io: you won’t have enough information to know whether it’s worth going through the trouble of following a link to another site and a lot of people wouldn’t bother.
So I don’t think that change really solves anything.
It’s really not possible to answer your question with the information you provided. Just saying “there’s an error” doesn’t tell us much.
You need to include actual code and the full error messages. Ideally, create a minimal example in the Rust playground that reproduces the issue and then link it: https://play.rust-lang.org/
Do you have suggestions what the future of lib.rs should be?
Not the same person, but my suggestions would be:
I think by taking that approach you’ll avoid a lot of the backlash because you are allowing people a choice.
I’m not a lawyer and this isn’t legal advice, but personally I’d be pretty careful about editorializing/moderating content in this kind of situation. Suppose someone publishes as crate that actively causes harm. Users download it and get their data stolen/wiped/whatever. Can they reasonably have an expectation that you should have protected them from that sort of thing? After all, you are editorializing the content and going so far as to moderate content that doesn’t cause direct immediate harm to an individual but even content that potentially is harmful to society.
Possibly I should disclose that I avoid lib.rs currently because I don’t agree with the philosophy of editorializing crates and personally I hate opinionated stuff that doesn’t give me choice/control. I use open source software/resources specifically because I care about having a choice. We don’t disagree philosophically on points like the harm of crypto such as bitcoin, I just don’t like this approach to dealing with it. Also, painting all crypto stuff with the same brush can potentially delay less (or maybe even non-?) harmful alternatives that don’t involve wasting massive amounts of computation to no end.
Look at your post and you’ll see my issue. :)