Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion to and from bool for CFBoolean #136

Merged
merged 1 commit into from Nov 27, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add conversion to and from bool for CFBoolean

  • Loading branch information
faern committed Nov 27, 2017
commit f0766c35c26d1da2698499488978157e96f9e320
@@ -43,3 +43,35 @@ impl CFBoolean {
}
}
}

impl From<bool> for CFBoolean {
fn from(value: bool) -> CFBoolean {
if value {
CFBoolean::true_value()
} else {
CFBoolean::false_value()
}
}
}

impl From<CFBoolean> for bool {
fn from(value: CFBoolean) -> bool {
value.0 == unsafe { kCFBooleanTrue }
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn to_and_from_bool() {
let b_false = CFBoolean::from(false);
let b_true = CFBoolean::from(true);
assert_ne!(b_false, b_true);
assert_eq!(b_false, CFBoolean::false_value());
assert_eq!(b_true, CFBoolean::true_value());
assert!(!bool::from(b_false));
assert!(bool::from(b_true));
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.