Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Add an error variant with shared ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 2, 2021
1 parent 7ea4775 commit 4200736
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io;
use std::result;
use std::str;
use std::string;
use std::sync::Arc;
use yaml_rust::emitter;
use yaml_rust::scanner::{self, Marker, ScanError};

Expand All @@ -28,6 +29,8 @@ pub enum ErrorImpl {
EndOfStream,
MoreThanOneDocument,
RecursionLimitExceeded,

Shared(Arc<ErrorImpl>),
}

#[derive(Debug)]
Expand Down Expand Up @@ -193,6 +196,7 @@ impl ErrorImpl {
"deserializing from YAML containing more than one document is not supported"
}
ErrorImpl::RecursionLimitExceeded => "recursion limit exceeded",
ErrorImpl::Shared(err) => err.description(),
}
}

Expand All @@ -202,6 +206,7 @@ impl ErrorImpl {
ErrorImpl::Io(err) => Some(err),
ErrorImpl::Utf8(err) => Some(err),
ErrorImpl::FromUtf8(err) => Some(err),
ErrorImpl::Shared(err) => err.source(),
_ => None,
}
}
Expand All @@ -227,6 +232,7 @@ impl ErrorImpl {
"deserializing from YAML containing more than one document is not supported",
),
ErrorImpl::RecursionLimitExceeded => f.write_str("recursion limit exceeded"),
ErrorImpl::Shared(err) => err.display(f),
}
}

Expand All @@ -241,6 +247,7 @@ impl ErrorImpl {
ErrorImpl::EndOfStream => f.debug_tuple("EndOfStream").finish(),
ErrorImpl::MoreThanOneDocument => f.debug_tuple("MoreThanOneDocument").finish(),
ErrorImpl::RecursionLimitExceeded => f.debug_tuple("RecursionLimitExceeded").finish(),
ErrorImpl::Shared(err) => err.debug(f),
}
}
}

0 comments on commit 4200736

Please sign in to comment.