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

chore: Replace ctor with std::sync::Once #115

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions pretty_assertions/Cargo.toml
Expand Up @@ -35,5 +35,3 @@ diff = "0.1.12"

[target.'cfg(windows)'.dependencies]
output_vt100 = "0.1.2"
ctor = "0.1.9"

25 changes: 20 additions & 5 deletions pretty_assertions/src/lib.rs
Expand Up @@ -84,12 +84,20 @@ use core::fmt::{self, Debug, Display};

mod printer;

#[doc(hidden)]
#[cfg(not(windows))]
pub fn __init() {}

#[doc(hidden)]
#[cfg(windows)]
use ctor::*;
#[cfg(windows)]
#[ctor]
fn init() {
output_vt100::try_init().ok(); // Do not panic on fail
pub fn __init() {
use std::sync::Once;

static START: Once = Once::new();

START.call_once(|| {
output_vt100::try_init().ok(); // Do not panic on fail
});
}

/// A comparison of two values.
Expand Down Expand Up @@ -241,6 +249,8 @@ macro_rules! assert_eq {
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
$crate::__init();

use $crate::private::CreateComparison;
::core::panic!("assertion failed: `(left == right)`{}{}\
\n\
Expand Down Expand Up @@ -287,6 +297,8 @@ macro_rules! assert_str_eq {
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
$crate::__init();

::core::panic!("assertion failed: `(left == right)`{}{}\
\n\
\n{}\
Expand Down Expand Up @@ -332,6 +344,8 @@ macro_rules! assert_ne {
match (&($left), &($right)) {
(left_val, right_val) => {
if *left_val == *right_val {
$crate::__init();

::core::panic!("assertion failed: `(left != right)`{}{}\
\n\
\nBoth sides:\
Expand Down Expand Up @@ -408,6 +422,7 @@ macro_rules! assert_matches {
(@ $left:expr, $right:expr, $maybe_colon:expr, $($arg:tt)*) => ({
match (&($left), &($right)) {
(left_val, right_val) => {
$crate::__init();
// Use the Display implementation to display the pattern,
// as using Debug would add another layer of quotes to the output.
struct Pattern<'a>(&'a str);
Expand Down