Skip to content

Commit

Permalink
Merge pull request #15 from blackbeam/xml
Browse files Browse the repository at this point in the history
Implement MARC XML
  • Loading branch information
blackbeam authored Apr 25, 2023
2 parents 514d08a + b7a178f commit d086652
Show file tree
Hide file tree
Showing 5 changed files with 482 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_and_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --verbose
args: --features default,xml --verbose
format_check:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ path = "src/lib.rs"
[features]
default = []
nightly = []
xml = ["dep:xml-rs"]

[dependencies]
xml-rs = { version = "0.8", optional = true }

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
no-default-features = true
features = ["default", "xml"]
34 changes: 33 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum Error {
UnexpectedSubfieldEnd,
NonUnicodeSequence(Pointer),
UnknownCharacterCodingScheme(u8),
Utf8Error(std::str::Utf8Error),
#[cfg(feature = "xml")]
XmlError(xml::writer::Error),
Io(io::ErrorKind),
}

Expand Down Expand Up @@ -65,14 +68,43 @@ impl fmt::Display for Error {
}
},
Error::Io(err) => write!(f, "IO error: {:?}", err),
Error::Utf8Error(err) => write!(f, "UTF8 error: {}", err),
#[cfg(feature = "xml")]
Error::XmlError(err) => write!(f, "XML error: {}", err),
}
}
}

impl ::std::error::Error for Error {}
impl ::std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::UnexpectedByteInDecNum(_)
| Error::FieldTooLarge(_)
| Error::RecordTooLarge(_)
| Error::RecordTooShort(_)
| Error::UnexpectedEofInDecNum
| Error::UnexpectedEof
| Error::UnexpectedEofInDirectory
| Error::NoRecordTerminator
| Error::UnexpectedSubfieldEnd
| Error::NonUnicodeSequence(_)
| Error::UnknownCharacterCodingScheme(_)
| Error::Io(_) => None,
Error::Utf8Error(ref e) => Some(e as &_),
#[cfg(feature = "xml")]
Error::XmlError(ref e) => Some(e as &_),
}
}
}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err.kind())
}
}

impl From<std::str::Utf8Error> for Error {
fn from(err: std::str::Utf8Error) -> Error {
Error::Utf8Error(err)
}
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ mod identifier;
mod indicator;
mod misc;
mod tag;
#[cfg(feature = "xml")]
mod xml;

pub use errors::*;

#[cfg(feature = "xml")]
#[doc(inline)]
pub use crate::xml::MarcXml;
#[doc(inline)]
pub use field::fields::Fields;
#[doc(inline)]
Expand Down
Loading

0 comments on commit d086652

Please sign in to comment.