You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The UpdateGistBuilder API has a pain point if you want to edit multiple files and don't know the quantity of files to edit until runtime. As an example, if we have a Vec<(String, String)> containing pairs of filenames and contents to update the gist with, the best way I found to create a builder is the following:
let builder = crab.gists().update(id);let data:Vec<(String,String)> = todo!();let iter = data.into_iter();letmut builder_with_files = None;ifletSome((file, content)) = iter.next(){
builder_with_files = Some(builder.file(file).with_content(content));}whileletSome((file, content)) = iter.next(){
builder_with_files = Some(builder_with_files.unwrap().file(file).with_content(content));}// Manual .map() due to async-nesslet gist = match builder_with_files {Some(builder) => Some(builder.send().await?),None => None,};
This is really ugly IMO and duplicates code more than it should. The problem here is that adding the first file is a type transformation of UpdateGistBuilder -> UpdateGistFileBuilder, whereas adding any subsequent files operates only on a UpdateGistFileBuilder. One way to fix this would require adding a way to obtain the original UpdateGistBuilder after adding a file, potentially by making UpdateGistFileBuilder::build public. However, there may also be other valid approaches.
The text was updated successfully, but these errors were encountered:
The
UpdateGistBuilder
API has a pain point if you want to edit multiple files and don't know the quantity of files to edit until runtime. As an example, if we have aVec<(String, String)>
containing pairs of filenames and contents to update the gist with, the best way I found to create a builder is the following:This is really ugly IMO and duplicates code more than it should. The problem here is that adding the first file is a type transformation of
UpdateGistBuilder -> UpdateGistFileBuilder
, whereas adding any subsequent files operates only on aUpdateGistFileBuilder
. One way to fix this would require adding a way to obtain the originalUpdateGistBuilder
after adding a file, potentially by makingUpdateGistFileBuilder::build
public. However, there may also be other valid approaches.The text was updated successfully, but these errors were encountered: