diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/interrupt-support | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/interrupt-support')
-rw-r--r-- | third_party/rust/interrupt-support/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | third_party/rust/interrupt-support/Cargo.toml | 6 | ||||
-rw-r--r-- | third_party/rust/interrupt-support/README.md | 4 | ||||
-rw-r--r-- | third_party/rust/interrupt-support/src/lib.rs | 46 |
4 files changed, 57 insertions, 0 deletions
diff --git a/third_party/rust/interrupt-support/.cargo-checksum.json b/third_party/rust/interrupt-support/.cargo-checksum.json new file mode 100644 index 0000000000..2530becc56 --- /dev/null +++ b/third_party/rust/interrupt-support/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"e4b1f4f6a20cfcbfdfe9e47a875a09d7c37e815953441000c62c191570bfa5de","README.md":"7f1418b4a7c138ba20bcaea077fe6cf0d6ffbaf6df6b90c80efc52aa0d0e2e9f","src/lib.rs":"d7311f1fe25c25e651fae85fcd734cd313331c580a050c31b8bf64d957aede0f"},"package":null}
\ No newline at end of file diff --git a/third_party/rust/interrupt-support/Cargo.toml b/third_party/rust/interrupt-support/Cargo.toml new file mode 100644 index 0000000000..3b86470637 --- /dev/null +++ b/third_party/rust/interrupt-support/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "interrupt-support" +version = "0.1.0" +authors = ["application-services@mozilla.com"] +license = "MPL-2.0" +edition = "2018" diff --git a/third_party/rust/interrupt-support/README.md b/third_party/rust/interrupt-support/README.md new file mode 100644 index 0000000000..5a9fbe5f39 --- /dev/null +++ b/third_party/rust/interrupt-support/README.md @@ -0,0 +1,4 @@ +## Interrupt crate + +This create exposes traits and errors to allow for interrupt support across +the various crates in this repository. diff --git a/third_party/rust/interrupt-support/src/lib.rs b/third_party/rust/interrupt-support/src/lib.rs new file mode 100644 index 0000000000..8a365e4adc --- /dev/null +++ b/third_party/rust/interrupt-support/src/lib.rs @@ -0,0 +1,46 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#![allow(unknown_lints)] +#![warn(rust_2018_idioms)] + +// Note that in the future it might make sense to also add a trait for +// an Interruptable, but we don't need this abstraction now and it's unclear +// if we ever will. + +/// Represents the state of something that may be interrupted. Decoupled from +/// the interrupt mechanics so that things which want to check if they have been +/// interrupted are simpler. +pub trait Interruptee { + fn was_interrupted(&self) -> bool; + + fn err_if_interrupted(&self) -> Result<(), Interrupted> { + if self.was_interrupted() { + return Err(Interrupted); + } + Ok(()) + } +} + +/// A convenience implementation, should only be used in tests. +pub struct NeverInterrupts; + +impl Interruptee for NeverInterrupts { + #[inline] + fn was_interrupted(&self) -> bool { + false + } +} + +/// The error returned by err_if_interrupted. +#[derive(Debug, Clone, PartialEq)] +pub struct Interrupted; + +impl std::fmt::Display for Interrupted { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("The operation was interrupted") + } +} + +impl std::error::Error for Interrupted {} |