Controlling failed memory allocations with panics in 3d party crate/lib

Hi all,

I have general question, how (and is it possible ?) to handle failed memory allocation with panics in 3d party library or crate.


New project, with some code written by myself, where I carefully handle all memory allocation errors with try_ methods, and avoid panics at any cost, redesigning application logic, even to use stack variables, stack arrays, stack strings and so on ... So no panics because of allocation failures are possible here.

3d party crates or libs I use, where I guess, no such kind of delicate treatments are. And they could possible use infallible collections. (A lot of crates use them .... )

So the question is, how to handle allocation errors and panics triggered in 3d library code ? The final goal is to survive and recover from the allocation error.

P.S. I have pretty enough examples, from real life, where services/daemons (written in C,C++) works perfectly after temporary situation with lack of free memory on the server, and I want to do the same in rust. At least, I don't want, to helplessly panic, when 3d party crate, was unable to push() only one element into vector...

You can't yet. There's work in progress to support downgrading std's allocation errors from an unconditional abort to just a panic, and you can catch panics thrown by 3rd party code:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.