22 个版本 (11 个稳定版)

3.1.1 2023年9月5日
3.1.0 2023年4月25日
2.0.0 2021年1月27日
1.5.0 2017年3月22日
0.2.2 2015年3月31日

#460解析器实现

Download history 43/week @ 2024-03-09 3/week @ 2024-03-16 31/week @ 2024-03-23 77/week @ 2024-03-30 14/week @ 2024-04-06 87/week @ 2024-04-13 27/week @ 2024-04-20 9/week @ 2024-04-27 20/week @ 2024-05-04 1/week @ 2024-05-11 3/week @ 2024-05-18 27/week @ 2024-05-25 17/week @ 2024-06-01 32/week @ 2024-06-08 64/week @ 2024-06-15 7/week @ 2024-06-22

每月131 次下载

MIT/Apache

97KB
2.5K SLoC

rust-marc 构建状态

MARC 21 书目格式的读取器和构建器。

安装

使用 cargo 包

文档

托管在 docs.rs

许可证

许可协议为以下之一

贡献

除非您明确说明,否则您有意提交的任何贡献,根据 Apache-2.0 许可协议定义,应按上述方式双许可,不得附加任何额外条款或条件。


lib.rs:

用于处理书目数据 MARC 21 格式的库

示例

读取

let input = fs::File::open("test/fixtures/3records.mrc")?;
let mut count = 0;

for (i, record) in Records::new(input).enumerate() {
    let record = dbg!(record?);
    match i {
        0 => assert_eq!(record.field(b"001")[0].get_data::<str>(), "000000002"),
        1 => assert_eq!(record.field(b"001")[0].get_data::<str>(), "000000005"),
        2 => assert_eq!(record.field(b"001")[0].get_data::<str>(), "000000009"),
        _ => panic!(),
    }
    count += 1;
}

assert_eq!(count, 3);

创建

let mut builder = RecordBuilder::new();
let record = builder
    .add_fields(fields!(
        control fields: [
            b"001" => "000000002",
            b"003" => "RuMoRGB",
        ];
        data fields: [
            b"979", b"  ", [
                b'a' => "autoref",
                b'a' => "dlopen",
            ],
        ];
    ))?
    .get_record()?;
assert_eq!(record.as_ref(), b"00100nam  2200061 i 4500001001000000003000800010\
    979002000018\x1E000000002\x1ERuMoRGB\x1E  \x1Faautoref\x1Fadlopen\x1E\x1D");

更新

let input = fs::File::open("test/fixtures/3records.mrc")?;
let orig_record = Records::new(input).next().expect("should be here")?;
let mut builder = RecordBuilder::from_record(&orig_record);
let record = builder
    // we'll replace `001`
    .filter_fields(|f| f.get_tag() != "001")
    .add_field((b"001", "foo"))?
    // we'll remove `979a` with value `dlopen` (note that an empty `979` will remain)
    .filter_subfields(|_, sf| sf.get_tag() != "979" ||
        sf.get_identifier() != 'a' ||
        sf.get_data::<str>() != "dlopen")
    .get_record()?;

assert_eq!(record.as_ref(), "01339nam a2200301 i 45000010004000000030008000040050017000120080\
    041000290170023000700350025000930400026001180410008001440720019001520840027001710840029001\
    980840029002271000076002562450352003322600025006843000011007096500092007207870038008128520\
    03400850852003400884856010400918979001201022979000301034\x1efoo\x1eRuMoRGB\x1e201507161647\
    15.0\x1e911009s1990    ru ||||  a    |00 u rus d\x1e  \x1fa91-8563А\x1fbRuMoRKP\x1e  \x1fa\
    (RuMoRGB)DIS-0000114\x1e  \x1faRuMoRGB\x1fbrus\x1fcRuMoRGB\x1e0 \x1farus\x1e 7\x1fa07.00.0\
    3\x1f2nsnr\x1e  \x1faЭ38-36-021.4,0\x1f2rubbk\x1e  \x1faТ3(6Ег)63-4,02\x1f2rubbk\x1e  \x1f\
    aТ3(5Ср)63-4,02\x1f2rubbk\x1e1 \x1faАбдувахитов, Абдужабар Абдусаттарович\x1e00\x1fa\"Брат\
    ья-мусульмане\" на общественно-политической арене Египта и Сирии в 1928-1963 гг. :\x1fbавт\
    ореферат дис. ... кандидата исторических наук : 07.00.03\x1fcАбдувахитов Абдужабар Абдусат\
    тарович ; Ташк. гос. ун-т\x1e  \x1faТашкент\x1fc1990\x1e  \x1fa17 с.\x1e 7\x1faВсеобщая ис\
    тория (соответствующего периода)\x1f2nsnr\x1e18\x1fw008120708\x1fiДиссертация\x1e4 \x1faРГ\
    Б\x1fbFB\x1fj9 91-4/2388-x\x1fx71\x1e4 \x1faРГБ\x1fbFB\x1fj9 91-4/2389-8\x1fx70\x1e41\x1fq\
    application/pdf\x1fuhttp://dlib.rsl.ru/rsl01000000000/rsl01000000000/rsl01000000002/rsl010\
    00000002.pdf\x1e  \x1faautoref\x1e  \x1e\x1d".as_bytes());

依赖关系

~63KB