These are chat archives for rust-lang/rust

1st
Mar 2017
Ewan Higgs
@ehiggs
Mar 01 2017 11:17
Was crates.io affected by the s3 hiccup? If so, I guess crates repo mirroring is bumped in priority?
Adam "Cezar" Jenkins
@emperorcezar
Mar 01 2017 15:43
If you think about it S3 had it's once every five years downtime, so good for a while now. :)
Ewan Higgs
@ehiggs
Mar 01 2017 15:47
if they go down again this week then they can front load the downtime and be good for like 10 years. ;)
Tomer Margalit
@matomer
Mar 01 2017 18:29
does anyone know how I can impl a trait for a generic trait? E.g. I have a trait Factoyr<R> and I'm trying to do impl<R, F:Factory<R>> X for F but it is rejected because R is unconstrained. I can't implement for Factory directly because the compiler can't make it into an object (and Box<Factory> doesn't help)
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:32
If you control the Factory trait, you could change R into an associated type.
Tomer Margalit
@matomer
Mar 01 2017 18:33
I don't control it it's something from a library
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:33
If that's not workable, then you'll have to include R as a parameter on X.
Tomer Margalit
@matomer
Mar 01 2017 18:34
ok, I'll do that
BTW, why does this constraint exist if R isn't used anywhere?
(in this impl)
on second thought that's no good. The whole point is to be able to pass X around. Once I include R in its parameter list I can't do that
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:37
Right.
In that case, there's nothing you can do to solve this, but that suggests that you're “solving the wrong problem.”
Tomer Margalit
@matomer
Mar 01 2017 18:39
is there anything that can be done in this case? the general problem is that I have a global (generic) factory trait and I don't want to pass it to each and every function I call (the factory creates buffers so it will be used all over). I was hoping to store it in a global static variable but in this case I can't do it
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:39
Ah.
Tomer Margalit
@matomer
Mar 01 2017 18:40
ok, do you have any suggestions ? :)
they are HW (GFX) buffers
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:42
Reify the trait.
I'll try and type out what I mean by that.
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:52
Actually, never mind, there’s an easier way.
Can you list out all the Resource types you’re planning to put in R?
Tomer Margalit
@matomer
Mar 01 2017 18:54
not really - it looks like it's kind of private. I tried doing the impl for the specific type returned by the function call but it didn't really work out
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:54
Because if you can, you can just do:
trait X: Factory<ResourceType1> + Factory<ResourceType2> + Factory<ResourceType3> {}
Tomer Margalit
@matomer
Mar 01 2017 18:55
wait I'll check if I can figure out the type of it
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:56
What function call is it?
I.e., what function are you calling?
Tomer Margalit
@matomer
Mar 01 2017 18:57
a call that creates a bunch of objects and one of them is a factory
init
:)
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:57
Does it come from a library?
Tomer Margalit
@matomer
Mar 01 2017 18:57
gfx_window_glutin::init::<ColorFormat, DepthFormat>(builder);
yes
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:57
Ah!
Hm.
Private type synonyms in a public interface. :worried:
Tomer Margalit
@matomer
Mar 01 2017 18:58
yes
:(
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:58
I’m looking at the source, and they’re all re-exports.
So import gfx_device_gl::Factory; that’s the Factory instance returned by init.
Tomer Margalit
@matomer
Mar 01 2017 18:59
ok I'll use that
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 18:59
device_gl there is an alias for gfx_device_gl
Tomer Margalit
@matomer
Mar 01 2017 19:00
was trying to make it more generic but I guess I'll do that
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 19:00
This is an instance where a library really should re-export any public types from a dependency that it uses in it’s own interface.
You can’t make this more generic with out higher-rank values.
Which is a feature Rust doesn’t have.
Tomer Margalit
@matomer
Mar 01 2017 19:00
because theoretically the Factory there returns a buffer completely independent of it's type param
*its
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 19:01
Yeah.
You would need to be able to say impl<for<R: Resource> F: Factory<R>>
Which may be coming with the work on associated type constructors, but even so it’s a ways off.
Tomer Margalit
@matomer
Mar 01 2017 19:02
I don't really know this syntax
but I tried <R, F: Factory<R>>
and rust doesn't like it
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 19:02
The for syntax exists in Rust today, but only works for lifetimes.
Tomer Margalit
@matomer
Mar 01 2017 19:02
ah
I see
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 19:02
You would need it to work for types in order to express what you want.
Tomer Margalit
@matomer
Mar 01 2017 19:03
although I really don't need R in this case... I'm looking at it as a function pointer
Alexander Ronald Altman
@pthariensflame
Mar 01 2017 19:03
But for your use case, just import the proper factory type from the underlying library. :)
Tomer Margalit
@matomer
Mar 01 2017 19:03
no need for any type info
yeah I'll do that, thanks :)