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
Building an Atom feed currently incurs many many allocations. Nearly every field of the type contains a String which mandates it be a separate and unique heap allocation. What's more, since all the .build() methods take &self they mandate cloning every single field in the builder. I think it would be good if atom_syndicator exposed a separate *Writer API for enabling feed-building without allocations. A sketch of what the API could look like is below:
pubstructFeedWriter<W>{/* ... */}impl<W:Write>FeedWriter<W>{pubfnfrom_writer(writer:W) -> Self{/* ... */}pubfntitle(&mutself) -> Result<TextWriter<'_,W>,Error>{/* set up the opening of a text tag */}pubfnid<Id:Display>(&mutself,id:Id) -> Result<&mutSelf,Error>{/* ... */}// etc// Automatically runs in the destructor of `FeedWriter`, but can be called here to handle errors.pubfnfinish(self) -> Result<W,Error>{/* ... */}}pubstructTextWriter<'a,W:Write>{/* ... */}impl<W:Write>TextWriter<'_,W>{pubfnset<Value:Into<Text>>(self,text:Value) -> Result<(),Error>{/* ... */}pubfnvalue<Value:Display>(&mutself,value:Value) -> Result<&mutSelf,Error>{/* ... */}pubfnbase<Base:Display>(&mutself,base:Base) -> Result<&mutSelf,Error>{/* ... */}// etc}impl<W:Write>DropforTextWriter<'_,W>{fndrop(&mutself){// finish writing out the text tag// In lieu of fallible destructors, errors from here can be pushed// up into the FeedWriter and returned on the next call to any one// of its methods.}}
As an alternative design, it's possible to collate all errors within the FeedWriter so that each individual method doesn't return a Result, but instead the first error is returned at .finish(). However that would mean it could force the user to do a lot more work than they need to do, since early returns on error conditions would not be possible.
Would such an API be possible to implement?
The text was updated successfully, but these errors were encountered:
Building an Atom feed currently incurs many many allocations. Nearly every field of the type contains a
String
which mandates it be a separate and unique heap allocation. What's more, since all the.build()
methods take&self
they mandate cloning every single field in the builder. I think it would be good ifatom_syndicator
exposed a separate*Writer
API for enabling feed-building without allocations. A sketch of what the API could look like is below:Such an API would be usable like so:
As an alternative design, it's possible to collate all errors within the
FeedWriter
so that each individual method doesn't return aResult
, but instead the first error is returned at.finish()
. However that would mean it could force the user to do a lot more work than they need to do, since early returns on error conditions would not be possible.Would such an API be possible to implement?
The text was updated successfully, but these errors were encountered: