Closed ctron closed 4 years ago
From what I understood, the Meta trait is immutable. However it would be nice to have a mutable version of that as well.
Meta
Assume the following scenario:
async fn create_or_update<T, F>( &self, reflector: &Reflector<T>, namespace: String, name: String, mutator: F, ) -> Result<()> where T: Clone + DeserializeOwned + Meta + Default + MetaMut, F: FnOnce(T) -> T, { let object = match reflector.get(&name).await { Err(e) => Err(e)?, Ok(None) => { let mut object: T = Default::default(); // allow setting meta object.meta_mut().replace(ObjectMeta { namespace: Some(namespace), name: Some(name), ..Default::default() }); mutator(object) } Ok(Some(object)) => mutator(object), }; writer.write(object) }
Other way could be:
object.meta_mut().set_namespace(namespace); object.meta_mut().set_name(name);
Meta is a kube trait, but yes k8s_openapi::Metadata should have a fn metadata_mut(&mut self) -> Option<&mut <Self as Metadata>::Ty> too.
kube
k8s_openapi::Metadata
fn metadata_mut(&mut self) -> Option<&mut <Self as Metadata>::Ty>
Awesome, thanks! Any plans on a new version? :grin:
From what I understood, the
Meta
trait is immutable. However it would be nice to have a mutable version of that as well.Assume the following scenario:
Other way could be: