#rust-lang

/

      • udoprog has quit
      • udoprog joined the channel
      • bdrewery has quit
      • cp joined the channel
      • hash joined the channel
      • hash has quit
      • hash joined the channel
      • sleffy joined the channel
      • hash has quit
      • oln has quit
      • kaknife has quit
      • kaknife joined the channel
      • kaknife has quit
      • Tobba joined the channel
      • Diggsey has quit
      • sleffy has quit
      • AstralSorcerer joined the channel
      • sleffy joined the channel
      • sleffy has quit
      • Noldorin has quit
      • sleffy joined the channel
      • kennytm has quit
      • sleffy has quit
      • kennytm joined the channel
      • tuna has quit
      • tuna joined the channel
      • tuna has quit
      • chill joined the channel
      • niconii has quit
      • Zoxc has quit
      • kennytm has quit
      • aismallard has quit
      • cp has quit
      • nox
      • nagisa joined the channel
      • Diggsey joined the channel
      • cp joined the channel
      • kennytm joined the channel
      • shiro joined the channel
      • Soni
        do you think these are a good fit for rust? https://internals.rust-lang.org/t/associated-st...
      • I'm trying to save my users some pain, suffering and confusion
      • in Java I'd do this with ASM/bytecode manipulation libs. doesn't quite work in Rust tho. ;)
      • centril
        Soni: it is interesting as a consistency fix, but I personally don't have uses for this.
      • Soni
        hmm I guess I could also try something with macros for the time being... are macros truly hygienic if e.g. they make a static and a trait impl? (at least then I can #[doc(hidden)] the stuff) it won't be the nicest thing in the world (it won't be nice at all) but might work??? idk
      • Mutabah
        Iirc, if you have multiple invocations of a macro that creates a static, there will be multiple statics
      • Soni
        oh ok, so they are hygienic, I guess
      • lukaramu joined the channel
      • as long as it doesn't error about two statics of the same name
      • shiro has quit
      • Mutabah
        eval: macro_rules! foo { ()=>{ static BLAH: u32 = 0; }} foo!() foo!()
      • NOTICE: error: expected one of `.`, `;`, `?`, `}`, or an operator, found `foo`
      • NOTICE: --> src/main.rs:3:66
      • NOTICE: ~~~ Output truncated; full output at https://play.rust-lang.org/?gist=d558359796ff96cafe9a91717a6c8d07&version=stable&mode=debug
      • eval: macro_rules! foo { ()=>{ static BLAH: u32 = 0; }} foo!{} foo!{}
      • NOTICE: error[E0428]: the name `BLAH` is defined multiple times
      • NOTICE: --> src/main.rs:3:34
      • NOTICE: ~~~ Output truncated; full output at https://play.rust-lang.org/?gist=6c80f435df497ec115015f21ade02911&version=stable&mode=debug
      • shiro joined the channel
      • aww....
      • I thouhgt that would work'
      • I think you can do scoping tricks though...
      • nox
        Use lazy_static in a method, return a reference to the lazily initialised value.
      • AstralSorcerer has quit
      • Soni
        I wonder how it'd handle monomorphization
      • associated statics handle monomorphization
      • so you could have an VecEvent<T>(Vec<T>) with associated statics
      • nox
        What does that even mean, and how is that different from a method using lazy_static internally and returning a reference from it?
      • The lazy_static is literally an implementation detail that doesn't escape the method, it doesn't matter wrt monomorphisation.
      • Mutabah
        If the impl is generic, the static won't be
      • Soni
      • nox
        Mutabah: The associated static in their link isn't generic.
      • Soni
        the associated static uses Self
      • which might be e.g. VecEvent<T>
      • Mutabah
        nox: Point
      • Soni
        I feel kinda dizzy bbl
      • centril
        I think a problem with associated statics is that it would __require__ every impl to have a static, which the impl might not need and would needlessly pay for
      • chordowl joined the channel
      • lukaramu has quit
      • oln joined the channel
      • JoshTriplett joined the channel
      • JoshTriplett has left the channel
      • Ericson2314_ joined the channel
      • Soni
        I'm back
      • centril: why associated consts ok but not associated statics?
      • if static storage space is an issue, it can be made lazily heap-allocated
      • in my case I do need every impl to have a static tho, so it fits perfectly
      • rkruppe joined the channel
      • nox
        "Be made lazily heap-allocated" = use lazy_static
      • Soni
        ... ok may I have an op
      • idk who's an op here
      • centril
        Soni: this is only _a_ problem... I'm not saying that it is make-or-break
      • Soni
        centril: this *can* be a problem, but if the *trait author* wants an optional static they can make it lazily heap-allocated and then the static is only the size of a pointer
      • nox
        fn foo() -> &Blah { lazy_static! { FOO: … = … } &FOO }
      • Soni
        my use case is the canonical use case for associated statics and can someone please ban nox already
      • centril
        Soni: sure, I understand this
      • nox
        Soni: What the hell are you saying?
      • I literally show you you don't need any associated statics for your use case and you want me banned?
      • centril
        Soni: no one is going to ban nox...
      • If you have an issue with a CoC violation, talk to a moderator, and don't ask for bans here..
      • But I'm confident there hasn't been a CoC violation.
      • Soni
        they keep derailing the conversation and they don't wanna listen to anything I have to say
      • also, I did ask for an op
      • eijebong joined the channel
      • nox
        I am not derailing the conversation when I show you that your use case is not "the canonical use case for associated statics", when I demonstrate you don't actually need "associated statics", either for performances or to avoid Hash uses or whatever.
      • Soni
        anyone knows if the playground does lazy static?
      • centril
        cc mbrubeck
      • djc
        Soni: it also looks to me like you're not listening very well to what nox has to say
      • centril
        or Manishearth
      • Soni
        nox: ok let me try it 1 sec
      • nox
        Soni: If you write `extern crate …` it autocompletes the included crates, lazy_static is part of them.
      • Soni
      • so you're saying it works?
      • nox
        Yeah, if you write it in a way that it doesn't work, it will not work.
      • Your issue isn't about associated statics, but about associated generics, now.
      • Manishearth
        Soni: no, I am not banning nox
      • Soni: every single conversation between you and nox, and in general between you and others, is you asking for language features, nox providing alternates or asking for clarification, and you ignoring it
      • mbrubeck
        Hey folks, if someone's answer to a technical question doesn't seem helpful, please either ignore it or ask for clarification; don't treat it as an attack (or as centril said, talk to a mod). Likewise if someone isn't receptive to your help, please feel free to just drop it.
      • nox
        There is not even an implementation of TestTrait in your snippet.
      • Soni
        nox: well ofc there isn't, why would I type the impls if it already doesn't even compile
      • the idea is that you'd do "impl TestTrait for AType" and "impl TestTrait for BType" and they'd have independent (associated) statics
      • mbrubeck
        On topic of associated statics, the summary of RFC 195 has a tantalizing bit of info https://rust-lang.github.io/rfcs/0195-associate...
      • nox
        If Rust had associated statics, it would still not compile.
      • Just like generic statics don't currently compile.
      • mbrubeck
        "This RFC was originally accepted before RFC 246 introduced the distinction between const and static items. The text has been updated to clarify that associated consts will be added rather than statics" but doesn't give more details
      • Manishearth
        Yeah -- there's nothing in Rust preventing us from adding associated statics, however there hasn't been much clear impetus either
      • Noldorin joined the channel
      • open an internals.rust-lang.org pre-rfc or thread and see if folks want it
      • Soni
      • Manishearth
        ah
      • good
      • wait and see if others want it. if so, write a proper pre-rfc
      • or rfc
      • centril
        mbrubeck: interesting! =P
      • Manishearth
        Soni: fwiw one of the reasons this probably won't happen is that you can imitate it by having a trait method that returns a &'static whatever
      • which works for your case too
      • (this same trick does not completely work for associated types or constants)
      • Soni
        Manishearth: I don't think that works
      • Manishearth
        Soni: why not?
      • Soni
        I mean, sure, I can return an associated static, but not give it a default value
      • Manishearth
        Soni: sure you can
      • Soni
        so what if I had struct VecEvent<T>(Vec<T>); and I wanted to impl Event for it?
      • Manishearth
        define a static within the function, return it
      • nox
      • mbrubeck
        Soni's playground link above was a good example of code that can't be done generically today; would require a macro or copy-pasting the impl
      • Soni
        with each Vec<T> having a separate "bus"
      • nox
        but that would fail to compile with associated statics too.
      • Soni
        what mbrubeck said
      • Manishearth
        you have not explained your bus system enough for that to make sense to me
      • Soni
        basically I don't wanna call handlers for VecEvent<i32> with a VecEvent<u32>
      • centril
        Manishearth: I could see this implemented purely for consistency reasons