Hacker News new | ask | show | jobs
by fnord123 3400 days ago
It sounds like you're coming from the land of GC. Rust helps a lot with managing memory but the pattern you're talking about is creating garbage which the GC would then have to collect.

Manually collect the things you need to hold onto and put them into a struct and return that from open_log(); Do the same with prepare_db(). Then give the structs some methods for getting to the actual db object.

Alternatively use log4rs and rust-postgres. Or inspect their code to see how they handle it.