Skip to main content

visionkit/
error.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5/// Represents why a VisionKit live text subject is unavailable.
6pub enum LiveTextSubjectUnavailable {
7    /// Represents a VisionKit subject image that could not be produced.
8    ImageUnavailable,
9}
10
11impl fmt::Display for LiveTextSubjectUnavailable {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            Self::ImageUnavailable => f.write_str("subject image is unavailable"),
15        }
16    }
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20/// Represents an error returned by the VisionKit wrappers.
21pub enum VisionKitError {
22    /// Represents an invalid-argument error from VisionKit.
23    InvalidArgument(String),
24    /// Represents a macOS availability error from VisionKit.
25    UnavailableOnThisMacOS(String),
26    /// Represents a platform availability error from VisionKit.
27    UnavailableOnThisPlatform(String),
28    /// Represents a timeout reported by VisionKit.
29    TimedOut(String),
30    NotOnMainThread(String),
31    MainRunLoopNotRunning(String),
32    /// Represents an unsupported-analyzer error from VisionKit.
33    AnalyzerNotSupported(String),
34    /// Represents a framework-level error from VisionKit.
35    Framework(String),
36    /// Represents a live text subject error from VisionKit.
37    LiveTextSubjectUnavailable(LiveTextSubjectUnavailable),
38    /// Represents an unknown error returned by VisionKit.
39    Unknown(String),
40}
41
42impl fmt::Display for VisionKitError {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Self::InvalidArgument(message)
46            | Self::UnavailableOnThisMacOS(message)
47            | Self::UnavailableOnThisPlatform(message)
48            | Self::TimedOut(message)
49            | Self::NotOnMainThread(message)
50            | Self::MainRunLoopNotRunning(message)
51            | Self::AnalyzerNotSupported(message)
52            | Self::Framework(message)
53            | Self::Unknown(message) => f.write_str(message),
54            Self::LiveTextSubjectUnavailable(kind) => kind.fmt(f),
55        }
56    }
57}
58
59impl Error for VisionKitError {}