Skip to content

Commit

Permalink
Restructure modules (#827)
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Wagner <[email protected]>
  • Loading branch information
nwagner84 authored Sep 11, 2024
1 parent ca7336b commit d739032
Show file tree
Hide file tree
Showing 13 changed files with 2,385 additions and 2,241 deletions.
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_record_ref.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use pica_record::RecordRef;
use pica_record::primitives::RecordRef;

fuzz_target!(|data: &[u8]| {
let _record = RecordRef::from_bytes(data);
Expand Down
38 changes: 3 additions & 35 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
use thiserror::Error;
use crate::primitives::ParsePicaError;

// macro_rules! bail {
// ($($tt:tt)*) => {{
// return Err(crate::error::Error::Other(format!($($tt)*)))
// }};
// }

// pub(crate) use bail;

/// An error that can occur in this library.
#[derive(Debug, Error)]
/// An error that can occur in this crate.
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
ParsePica(ParsePicaError),

#[error("{0}")]
Other(String),
}

/// An error that can occur when parsing PICA+ records.
#[derive(Debug, Error)]
pub enum ParsePicaError {
#[error("'{0}' is not a valid subfield code.")]
SubfieldCode(char),
#[error("'{0}' is not a valid subfield value.")]
SubfieldValue(String),
#[error("'{0}' is not a valid subfield.")]
Subfield(String),
#[error("'{0}' is not a valid tag.")]
Tag(String),
#[error("'{0}' is not a valid occurrence.")]
Occurrence(String),
#[error("'{0}' is not a valid field.")]
Field(String),
#[error("'{0}' is not a valid record.")]
Record(String),
#[error("'{0}' is not a valid string record.")]
StringRecord(String),
}
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
//! encoded in (normalized) PICA+, the internal data format of the
//! [OCLC](https://www.oclc.org) cataloging system.

pub use error::{Error, ParsePicaError};
pub use record::{
ByteRecord, Field, FieldRef, Level, Occurrence, OccurrenceRef,
Record, RecordRef, StringRecord, Subfield, SubfieldCode,
SubfieldRef, SubfieldValue, SubfieldValueRef, Tag, TagRef,
};
pub use error::Error;
pub use record::{ByteRecord, StringRecord};

pub mod primitives;

mod error;
pub mod prelude;
mod record;
17 changes: 17 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! General-use types and traits from this crate.
//!
//! This module contains the most used types, type aliases, traits,
//! functions and macros for glob import.
//!
//! # Example
//!
//! ```rust
//! use pica_record::prelude::*;
//!
//! let record = ByteRecord::from_bytes(b"002@ \x1f0Olfo\x1e\n")?;
//! assert!(record.validate().is_ok());
//!
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```

pub use crate::{ByteRecord, Error, StringRecord};
6 changes: 6 additions & 0 deletions src/primitives/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use thiserror::Error;

/// An error that can occur when parsing PICA+ records.
#[derive(Debug, Error)]
#[error("{0}")]
pub struct ParsePicaError(pub(crate) String);
Loading

0 comments on commit d739032

Please sign in to comment.