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    /// Represents an unsupported-analyzer error from VisionKit.
31    AnalyzerNotSupported(String),
32    /// Represents a framework-level error from VisionKit.
33    Framework(String),
34    /// Represents a live text subject error from VisionKit.
35    LiveTextSubjectUnavailable(LiveTextSubjectUnavailable),
36    /// Represents an unknown error returned by VisionKit.
37    Unknown(String),
38}
39
40impl fmt::Display for VisionKitError {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            Self::InvalidArgument(message)
44            | Self::UnavailableOnThisMacOS(message)
45            | Self::UnavailableOnThisPlatform(message)
46            | Self::TimedOut(message)
47            | Self::AnalyzerNotSupported(message)
48            | Self::Framework(message)
49            | Self::Unknown(message) => f.write_str(message),
50            Self::LiveTextSubjectUnavailable(kind) => kind.fmt(f),
51        }
52    }
53}
54
55impl Error for VisionKitError {}