Skip to content

Commit

Permalink
Replace void crate with std::convert::Infallible.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Sep 29, 2023
1 parent 6fb106a commit c4a941b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion deepwell/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion deepwell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ toml = { version = "0.8", features = ["parse"] }
typenum = "1"
unic-langid = "0.9"
unicase = "2"
void = "1"
wikidot-normalize = "0.11"
wikidot-path = "0.5"

Expand Down
15 changes: 12 additions & 3 deletions deepwell/src/services/blob/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use super::prelude::*;
use crossfire::mpsc;
use filemagic::{FileMagicError, Flags as MagicFlags, Magic};
use std::convert::Infallible;
use std::sync::Once;
use std::{process, thread};
use void::{ResultVoidErrExt, Void};

type ResponsePayload = StdResult<String, FileMagicError>;
type ResponseSender = mpsc::TxBlocking<ResponsePayload, mpsc::SharedSenderBRecvF>;
Expand All @@ -58,7 +58,7 @@ macro_rules! source {
};
}

fn main_loop() -> Result<Void> {
fn main_loop() -> Result<Infallible> {
const MAGIC_FLAGS: MagicFlags = MagicFlags::MIME;
const MAGIC_PATHS: &[&str] = &[]; // Empty indicates using the default magic database

Expand All @@ -81,11 +81,20 @@ fn main_loop() -> Result<Void> {
pub fn spawn_magic_thread() {
static START: Once = Once::new();

macro_rules! unwrap_err {
($result:expr) => {
match $result {
Ok(_) => unreachable!(),
Err(error) => error,
}
};
}

START.call_once(|| {
thread::spawn(|| {
// Since this is an infinite loop, no success case can return.
// Only the initialization can fail, individual requests just pass back the result.
let error = main_loop().void_unwrap_err();
let error = unwrap_err!(main_loop());
tide::log::error!("Failed to spawn magic thread: {error}");
process::exit(1);
});
Expand Down
4 changes: 2 additions & 2 deletions deepwell/src/services/job/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::services::{PageRevisionService, SessionService, TextService};
use async_std::task;
use crossfire::mpsc;
use sea_orm::TransactionTrait;
use std::convert::Infallible;
use std::sync::Arc;
use void::Void;

lazy_static! {
static ref QUEUE: (mpsc::TxUnbounded<Job>, mpsc::RxUnbounded<Job>) =
Expand Down Expand Up @@ -109,7 +109,7 @@ impl JobRunner {
// see config.refill_name_change
}

async fn main_loop(mut self) -> Void {
async fn main_loop(mut self) -> Infallible {
tide::log::info!("Starting job runner");

let delay = self.state.config.job_delay;
Expand Down
4 changes: 2 additions & 2 deletions deepwell/src/services/page_query/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::models::page_parent::{self, Entity as PageParent};
use crate::models::{page_revision, text};
use crate::services::{PageService, ParentService};
use sea_query::{Expr, Query};
use void::Void;
use std::convert::Infallible;

#[derive(Debug)]
pub struct PageQueryService;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl PageQueryService {
pagination,
variables,
}: PageQuery<'_>,
) -> Result<Void> {
) -> Result<Infallible> {
tide::log::info!("Building ListPages query from specification");

let txn = ctx.transaction();
Expand Down

0 comments on commit c4a941b

Please sign in to comment.