#Compiler is complaining

11 messages · Page 1 of 1 (latest)

sacred gulch
#

hello, rust beginner here, i have the following code and the compiler is complaining, i would say that i understand why is it doing so, but i don't quite know how to solve it, can i somehow move the ownership of the shader_module to the struct which i am trying to create and then reference it in the fragment_state? Or is there any other way? Thank you!

frosty furnace
#

fragment_state has a ref to shader_module, which is dropped at the end of the function

obsidian plume
#

you need to separate the steps of 'create and return the shader module' from 'make a FragmentState that refers to it'

#

these cannot be in the same function

#

in my experience, a wgpu::FragmentState will fit nicely into constructing the containing RenderPipelineDescriptor

frosty furnace
#

You could also store shader_module in Self

obsidian plume
#

note that you can write a method on FragmentShader that returns the wgpu::FragmentState (which will then borrow from the FragmentShader)

sacred gulch
#

so i should split it into two functions, something like new() and init(&self), new() will create struct with shader_module and in the init(&self) i can reference it while creating wgpu::FragmentState?

obsidian plume
#

yes, but it's not really an init

#

think create_fragment_state(&self) -> wgpu::FragmentState<'_>