├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── examples └── main.rs └── src └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lovecraft" 3 | version = "0.2.0" 4 | authors = ["Geoffroy Couprie "] 5 | edition = "2018" 6 | description = "brings back the Lovecraft quotes on panic" 7 | license = "MIT" 8 | repository = "https://github.com/Geal/lovecraft" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/lovecraft" 11 | 12 | [dependencies] 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Geoffroy Couprie 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # You've met with a terrible fate, haven't you? 2 | 3 | Long ago, every Rust program came with a set of Lovecraft quotes that would 4 | be displayed on panic. Unfortunately, for [a lot of important reasons](https://github.com/rust-lang/rust/issues/13871) 5 | like making "hello world" programs smaller, they were removed. 6 | 7 | Thankfully, this crate brings disorder and dread back into your programs. 8 | 9 | With the following code: 10 | 11 | ```rust 12 | extern crate lovecraft; 13 | 14 | fn main() { 15 | lovecraft::invoke(); 16 | 17 | panic!("Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn"); 18 | } 19 | ``` 20 | 21 | This will print: 22 | 23 | ``` 24 | $ ./main 25 | Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn 26 | 27 | It was from the artists and poets that the pertinent answers came, and I 28 | know that panic would have broken loose had they been able to compare notes. 29 | As it was, lacking their original letters, I half suspected the compiler of 30 | having asked leading questions, or of having edited the correspondence in 31 | corroboration of what he had latently resolved to see. 32 | ``` 33 | 34 | You can also choose your own quotes with the function: `lovecraft::panic_quotes(quotes: &'static [&'static str], default: &'static str)` 35 | 36 | -------------------------------------------------------------------------------- /examples/main.rs: -------------------------------------------------------------------------------- 1 | extern crate lovecraft; 2 | 3 | fn main() { 4 | lovecraft::invoke(); 5 | 6 | panic!("Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn"); 7 | } 8 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::panic; 2 | 3 | /// restore the Lovecraft quotes on panic, as it should be 4 | pub fn invoke() { 5 | panic_quotes( 6 | &LOVECRAFT_QUOTES, 7 | "You've met with a terrible fate, haven't you?", 8 | ); 9 | } 10 | 11 | /// use panic quotes to your own taste 12 | pub fn panic_quotes(quotes: &'static [&'static str], default: &'static str) { 13 | panic::set_hook(Box::new(move |panic_info| { 14 | match panic_info.payload().downcast_ref::<&str>() { 15 | None => println!("{}", default), 16 | Some(msg) => { 17 | let hash = msg.len(); 18 | let quote = quotes[hash % quotes.len()]; 19 | println!("{}\n\n{}", msg, quote); 20 | } 21 | } 22 | })); 23 | } 24 | 25 | const LOVECRAFT_QUOTES: [&'static str; 10] = [ 26 | "It was from the artists and poets that the pertinent answers came, and I 27 | know that panic would have broken loose had they been able to compare notes. 28 | As it was, lacking their original letters, I half suspected the compiler of 29 | having asked leading questions, or of having edited the correspondence in 30 | corroboration of what he had latently resolved to see.", 31 | "There are not many persons who know what wonders are opened to them in the 32 | stories and visions of their youth; for when as children we listen and dream, 33 | we think but half-formed thoughts, and when as men we try to remember, we are 34 | dulled and prosaic with the poison of life. But some of us awake in the night 35 | with strange phantasms of enchanted hills and gardens, of fountains that sing 36 | in the sun, of golden cliffs overhanging murmuring seas, of plains that stretch 37 | down to sleeping cities of bronze and stone, and of shadowy companies of heroes 38 | that ride caparisoned white horses along the edges of thick forests; and then 39 | we know that we have looked back through the ivory gates into that world of 40 | wonder which was ours before we were wise and unhappy.", 41 | "Instead of the poems I had hoped for, there came only a shuddering blackness 42 | and ineffable loneliness; and I saw at last a fearful truth which no one had 43 | ever dared to breathe before — the unwhisperable secret of secrets — The fact 44 | that this city of stone and stridor is not a sentient perpetuation of Old New 45 | York as London is of Old London and Paris of Old Paris, but that it is in fact 46 | quite dead, its sprawling body imperfectly embalmed and infested with queer 47 | animate things which have nothing to do with it as it was in life.", 48 | "The ocean ate the last of the land and poured into the smoking gulf, thereby 49 | giving up all it had ever conquered. From the new-flooded lands it flowed 50 | again, uncovering death and decay; and from its ancient and immemorial bed it 51 | trickled loathsomely, uncovering nighted secrets of the years when Time was 52 | young and the gods unborn. Above the waves rose weedy remembered spires. The 53 | moon laid pale lilies of light on dead London, and Paris stood up from its damp 54 | grave to be sanctified with star-dust. Then rose spires and monoliths that were 55 | weedy but not remembered; terrible spires and monoliths of lands that men never 56 | knew were lands...", 57 | "There was a night when winds from unknown spaces whirled us irresistibly into 58 | limitless vacuum beyond all thought and entity. Perceptions of the most 59 | maddeningly untransmissible sort thronged upon us; perceptions of infinity 60 | which at the time convulsed us with joy, yet which are now partly lost to my 61 | memory and partly incapable of presentation to others.", 62 | "You've met with a terrible fate, haven't you?", 63 | "You've met with a terrible fate, haven't you?", 64 | "You've met with a terrible fate, haven't you?", 65 | "You've met with a terrible fate, haven't you?", 66 | "You've met with a terrible fate, haven't you?", 67 | ]; 68 | --------------------------------------------------------------------------------