Please consider contacting a service where you will be listened to and not judged. Lifeline, Samaritans, helplines, because bottling this up is dangerous for you. We all need support in these crisis situations, and you have done a good thing by posting here for a start. Well done for that. Please try not to judge yourself harshly - when the world is beating up on you, don't join in and victimise yourself too - you are already in enough pain. You can and will get through this.
Will things get better in years to come? All I can tell you is that was true for me, and I have lived much longer than you. You get older, you know better - we pick up a lot of experience along the way - and you do better because you know better.
Right now this learning curve is very harsh and painful for you. I understand that. The first four decades of my life were far more troubled and unhappy than the following three decades. None of us can know the future, for sure, though it is premature to regard it as hopeless at this stage of your life. What is certain is that you are in a lot of pain, an enormous amount, and you need careful support as you process it and restabalise your life.
I find comfort in an old Japanese proverb about the meaning of success: "fall down 99 times, get up once". I can absolutely tell you that in the course of life, I learned far far more from my failures than my successes, and that without my earlier failures, there wouldn't have been later success.
When you are recovered from this traumatic set of events, it might be worth considering working with a career professional to identify your major strengths and the best niches for their use, and ways of playing to them. But for know, the most important thing is to be kind and gentle to yourself, don't get too isolated, and tread yourself with respect. Another old (and wise) maxim to bear in mind is that the only failure is never to try. So you haven't failed yet.
If you are unable for some reason to access a support line, then look for support in a group. Somewhere there will be a group for you and you will find welcome and support there.
A book that got me through a terrible time in my life, when I too was badly wounded, hurting and alone was Laura Day's "Welcome to Your Crisis" which I found in the library. She wrote it after suffering terrible circumstances which brought her to absolute despair, and it describes her journey to recovery. Not everyone's journey is the same, and hers was different from mine, though in every page I found connection, because she really did know how I was feeling (shattered, worn out, alone, hopeless) and she could communicate that understanding. She got me through it, a total stranger, so help can arrive in very different ways. Her encouragement and support led me to make some very life changing decisions that same day (as I read her book) which led me in a new and healing direction.
I wish you the same experience, ie finding that gateway from despair to hope, and going through it. You are clearly an articulate person and one who has great perseverance skills. These and other strong qualities will still be there when the pain diminishes. All the best for the future, and I feel for the pain you are currently in.