Skip to content

Commit

Permalink
Add basic CFError Display and Error impls
Browse files Browse the repository at this point in the history
Part of #692.
  • Loading branch information
madsmtm committed Jan 11, 2025
1 parent 933f49c commit 4b630ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions framework-crates/objc2-core-foundation/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![cfg(all(feature = "CFBase", feature = "CFString"))]
use core::fmt;

use crate::{CFError, CFErrorCopyDescription};

impl fmt::Display for CFError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let desc = unsafe { CFErrorCopyDescription(self) }.unwrap();
write!(f, "{desc}")
}
}

#[cfg(feature = "std")] // use core::error::Error from Rust 1.81 once in MSRV.
impl std::error::Error for CFError {}
2 changes: 2 additions & 0 deletions framework-crates/objc2-core-foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mod cf_type;
mod data;
#[cfg(feature = "CFDate")]
mod date;
#[cfg(feature = "CFError")]
mod error;
mod generated;
#[cfg(feature = "CFCGTypes")]
mod geometry;
Expand Down

0 comments on commit 4b630ef

Please sign in to comment.