« first day (1622 days earlier)      last day (1866 days later) » 

12:05 AM
There is likely more to come, but it's public now. I present heel-gun to you.
 
12:20 AM
0
Q: In Rust how can I implement a reusable function that depends on a for-each style loop that executes behavior

10coolLets say I have some 2d grid data represented as a 1d array and I want to print it out in grid form. I would implement a display function to process the data and print it in grid form like so: fn main() { struct GridData { propA: u32, propB: f32, } let rows = 5; ...

I started some code and then realized
they are simply too many way to do this
I don't find "the ultimate one" cause the question is too unclear
want use display ? want to be generic ? at what point ?
@Shepmaster what the problem with "," ???
I die
 
 
1 hour later…
1:37 AM
@Stargateur I hope that's because they needed a named function to be referenced from somewhere
 
@Shepmaster they can't use doc.rust-lang.org/std/ops/trait.Not.html somehow ?
 
2:16 AM
@Stargateur if it’s what I think, then it wants &T. Is Not implemented for &bool?
 
this should work in place of their function no ?
even for ref
oh indeed
doesn't work with ref
but not it's implemented for &'a bool
haha
that work xd
 
@Stargateur you could write Not::not too
 
@FrancisGagné much better I tried Not compiler didn't hint me Not::not
 
 
6 hours later…
8:31 AM
0
Q: console.log returns result with proper HTML escape sequence but not in any other way?

Chris Mathew GeorgeI made a node js package using rust and neon-cli for making use of a rust crate (syntect by trishume) that I wanted to use for a long time. When I called node and console logged the value, the log was what I desired, however when I gave it to a variable and wrote the variables name it returned he...

my heart
new user I will pass my turn
 
 
3 hours later…
11:43 AM
Holy run-on sentence, Batman
 
12:35 PM
@FrancisGagné @Stargateur so the functions are used in some macro:
    #[oauth1(option, encoded, fmt = "fmt_follow")]
    follow: Option<&'a [u64]> = None,
I wonder if the macro doesn't allow for paths, which would preclude Not::not
(this library doesn't seem great, so I'm really reaching for straws here)
 
I don't understand the purpose
 
Just that it's all in that def_stream! {
 
outch
 
(deleted: nevermind)
 
nope still don't understand anything xd
but they can do this #[oauth1(skip_if = "::std::option::Option::is_none", fmt = "super::fmt_option_str")]
 
12:45 PM
@Stargateur ah, then all my ideas are gone.
Submit an issue :-)
 
@Shepmaster maybe ^^
error[E0308]: mismatched types
   --> src\lib.rs:137:22
    |
137 |             #[derive(OAuth1Authorize)]
    |                      ^^^^^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter
    |
    = note: expected type `for<'r> fn(&'r _) -> bool`
               found type `fn(_) -> <_ as std::ops::Not>::Output {<_ as std::ops::Not>::not}`
 
@Stargateur Ah.
let skip_if: fn(&_) -> bool = #skip_if;
which I don't know why they do that...
 
error: invalid path: "<&bool>::not" damm
bool::not almost compile just the reference problem
 
 
2 hours later…
2:47 PM
@E_net4 Fun!
 
@набиячлэвэли Hello there. That's a safe move indeed.
Issue #885 in the same repo is a good read too. Makes me wish we had been pinged sooner.
 
Pinged? I just opened that PR by accident :v
 
Right. Never mind.
I was working on this right now, in fact.
 
that confirm I don't like piston dev team... ^^
 
2:53 PM
// A
#[snafu(display("hi {}", bar))]
#[snafu(visibility(pub(crate)))]
#[snafu(backtrace(delegate))]

// B
#[snafu(display = ("hi {}", bar))]
#[snafu(visibility = pub(crate))]
#[snafu(backtrace = delegate)]
Which do you like better ^
 
The bad news is that I can't do any miracles here. The crate will have to take the hit.
@Stargateur How so?
 
"I'm sorry if this feels like a rather harsh reaction but UB like that is a red rag for me especially for a crate stating it tries to make this safe and that feels like a huge broken promise."
specially "At this point I consider removing the dependency from image because it is surely one of its biggest contributors to their popularity ranking on crates.io and I just don't feel like endorsing it in the current state?"
also I found stupid to drop a crate and implement the same feature by hand
why not fork the crate or help
they use it for free
and complain
and also the typical "Rgb is defined as #[repr(C)] in color.rs. See the define_colors macro. It's still pretty sketchy, but I'm not convinced it's unsound."
 
@Stargateur FWIW, their implementation was not the same as ours, they used a method that breaks the purpose of the crate itself, so even if they gave us that implementation, it would deviate from safe-transmute's goals.
 
so there are doing more unsafe thing ?
 
@Stargateur We did receive feedback regarding vector transmutations.
@Stargateur Only the vec_u16_copy_u8 method is a bit dubious here. They ought to make internal constraints for that to be safe, which we cannot make when building a library. Everything else does not use unsafe, I notice.
Hmm, I see it now, they turn the input vector into a slice, transmute the slice, then to_owned into a Vec. The middle part is just about what we do in safe_transmute for slices.
 
3:14 PM
Whelp, at this point I just want to remove the dangerous parts and let it be. The lesson is learned: turning unsafe stuff into safe stuff is hard.
 
that unclear to me
every thing should be u8 aligned
 
@Stargateur Uh, what?
 
In C, you can convert anything to char *
and there is a good reason to that
I don't understand why the mcve give in the feedback bug
 
@Stargateur Yes, interpreting some well defined buffer as a sequence of bytes is fine. But it's not fine to assume that they are owned by a vector of bytes.
In other terms: &[T] -> &[u8] can be made safe, whereas Vec<T> -> Vec<u8> isn't always safe.
 
I see cause rust way to dealocate is more user side than C
is there a way to transform Vec<T> -> GuardVec<u8> that will do the magic ?
remember to drop as a Vec<T> and behave like a Vec<u8>
 
3:30 PM
@Stargateur Yes, and I did think about doing that. :) But in the end, it sort of breaks the purpose of having the function in the first place. We can no longer use GuardVec<u8> where one would have a Vec<u8>.
 
@Shepmaster B add some space
 
Instead, we'll have to tell people to create safe views on top of vectors (&Vec<T> -> &[u8]).
 
maybe you could use some recursivity
but at least have a "view" is something
better than UB ^^
or just have the guard<u8> and a method into_inner
this allow Vec<T> => Guard<u8>, Guard<u8> => Vec<T>
 
@Stargateur Yes, could be a small benefit in there: the wrapper could override the Deref target type directly to the intended type.
Might be worth making this at a later stage.
Regretfully, I can no longer think of a safe way to turn a Vec<u8> into a Vec<T>. Better give up on that one.
 
there is not
we have the proof in the feedback
oh you mean u8 => T
that for sure is impossible
 
3:54 PM
Yup, there we go. I ought to stop using it in nifti too. :[
 
4:05 PM
Hmm, long stack trace we have here.
 
@E_net4 a legit one
 
4:47 PM
 
5:00 PM
hurr durr
 
5:57 PM
@E_net4 Ferris take the wheel
 
@набиячлэвэли Haw haw
PR incoming
Wait what, someone already starred my heel gun.
 
 
1 hour later…
7:07 PM
Yes, I'm answering a sort-of dupe. In my defense, the other q was pretty old. :/
 
7:45 PM
@E_net4 my question, you mean?
 
@Shepmaster :x
 
Lawd knows I don't like to update questions and answers
Ok, pop quiz.
 
:x
 
type Result<T, E = ()> = std::result::Result<T, E>;

fn foo(i: impl IntoIterator<Item = u8>) -> Result<Vec<bool>> {
    i.into_iter().what(bar).goes().here()
}

fn bar(_: u8) -> Result<Vec<bool>> {
    Ok(vec![true, false, true])
}
I want a "flat map handling result"
 
8:38 PM
@Shepmaster Something deep inside tells me I would've used that too.
 
9:17 PM
type Result<T, E = ()> = std::result::Result<T, E>;

fn foo(i: impl IntoIterator<Item = u8>) -> Result<Vec<bool>> {
    i.into_iter()
        .map(bar)
        .collect::<Result<Vec<_>>>()
        .map(|v| v.into_iter().flat_map(|w| w).collect())
}

fn bar(_: u8) -> Result<Vec<bool>> {
    Ok(vec![true, false, true])
}
@Shepmaster ^
not necessarily efficient, but should work
type Result<T, E = ()> = std::result::Result<T, E>;

fn foo(i: impl IntoIterator<Item = u8>) -> Result<Vec<bool>> {
    i.into_iter().try_fold(vec![], |mut acc, x| {
        bar(x).map(|r| {
            acc.extend(r);
            acc
        })
    })
}

fn bar(_: u8) -> Result<Vec<bool>> {
    Ok(vec![true, false, true])
}
shorter:
type Result<T, E = ()> = std::result::Result<T, E>;

fn foo(i: impl IntoIterator<Item = u8>) -> Result<Vec<bool>> {
    i.into_iter().try_fold(vec![], |mut acc, x| {
        acc.extend(bar(x)?);
        Ok(acc)
    })
}

fn bar(_: u8) -> Result<Vec<bool>> {
    Ok(vec![true, false, true])
}
if Add<Vec<T>> was implemented for Vec<T> then it could be even shorter:
fn foo(i: impl IntoIterator<Item = u8>) -> Result<Vec<bool>> {
    i.into_iter().try_fold(vec![], |acc, x| Ok(acc + bar(x)?))
}
 
9:39 PM
I did the double collect myself first. Just feels so wrong.
I’d probably use try_fold in a different project, but I’m trying to support Rust 1.18 (yeeeeee)
I just did ye olde for loop with a match for now.
 
@E_net4 wow, your PR is so thick and juicy
not sure I'll get a chance to review it before going ~away~ for the week
 
10:04 PM
@Shepmaster that's what I would do
 
@набиячлэвэли Take your time. Although we've been for a long time between major releases, this really isn't something we should be rushing.
The credibility of the crate is at stake, after all
 
har har
this is a наб™ branded product, it's doomed from the get-go
 
:|
Speaking of credibility and stuff, I'll be adding the shiny "no unsafe" attribute to heel-gun.
Too bad I can't do this for bra.
(yes my bra has unsafe mechanisms, roflroflrofl)
 

« first day (1622 days earlier)      last day (1866 days later) »