Skip to content

Commit

Permalink
chore: fix export of bindle-related types
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 8, 2023
1 parent b2b6786 commit e0f4558
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 46 deletions.
83 changes: 40 additions & 43 deletions src/containers/bindle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
use std::collections::BTreeMap;
use std::fmt::{Debug, Display};
use std::io::Read;
use std::io::{self, Read};
use std::ops::Deref;
use std::str::FromStr;

#[cfg(feature = "fs")]
pub use _fs::*;
use amplify::confinement;
use amplify::confinement::{Confined, TinyVec, U24};
use amplify::confinement::{self, Confined, TinyVec, U24};
use baid58::Baid58ParseError;
use rgb::{BundleId, ContractId, Schema, SchemaId, SchemaRoot, SubSchema};
use strict_encoding::{
Expand Down Expand Up @@ -294,6 +291,31 @@ impl<C: BindleContent> Bindle<C> {
}
}

#[derive(Clone, Debug, From)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase", tag = "type")
)]
pub enum UniversalBindle {
#[from]
#[cfg_attr(feature = "serde", serde(rename = "interface"))]
Iface(Bindle<Iface>),

#[from]
Schema(Bindle<SubSchema>),

#[from]
#[cfg_attr(feature = "serde", serde(rename = "implementation"))]
Impl(Bindle<IfaceImpl>),

#[from]
Contract(Bindle<Contract>),

#[from]
Transfer(Bindle<Transfer>),
}

impl UniversalBindle {
pub fn load(mut data: impl Read) -> Result<Self, LoadError> {
let mut rgb = [0u8; 3];
Expand All @@ -315,53 +337,28 @@ impl UniversalBindle {
}
}

#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum LoadError {
/// invalid file data.
InvalidMagic,

#[display(inner)]
#[from]
#[from(io::Error)]
Decode(strict_encoding::DecodeError),
}

#[cfg(feature = "fs")]
mod _fs {
use std::io::Write;
use std::path::Path;
use std::{fs, io};

use strict_encoding::{DecodeError, StrictEncode, StrictWriter};
use strict_encoding::{StrictEncode, StrictWriter};

use super::*;

#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum LoadError {
/// invalid file data.
InvalidMagic,

#[display(inner)]
#[from]
#[from(io::Error)]
Decode(DecodeError),
}

#[derive(Clone, Debug, From)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase", tag = "type")
)]
pub enum UniversalBindle {
#[from]
#[cfg_attr(feature = "serde", serde(rename = "interface"))]
Iface(Bindle<Iface>),

#[from]
Schema(Bindle<SubSchema>),

#[from]
#[cfg_attr(feature = "serde", serde(rename = "implementation"))]
Impl(Bindle<IfaceImpl>),

#[from]
Contract(Bindle<Contract>),

#[from]
Transfer(Bindle<Transfer>),
}

impl<C: BindleContent> Bindle<C> {
pub fn load_file(path: impl AsRef<Path>) -> Result<Self, LoadError> {
let file = fs::File::open(path)?;
Expand Down
4 changes: 1 addition & 3 deletions src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ mod util;
mod validate;
mod certs;

pub use bindle::{Bindle, BindleContent, BindleParseError};
#[cfg(feature = "fs")]
pub use bindle::{LoadError, UniversalBindle};
pub use bindle::{Bindle, BindleContent, BindleParseError, LoadError, UniversalBindle};
pub use certs::{Cert, ContentId, ContentSigs, Identity};
pub use consignment::{Consignment, Contract, Transfer};
pub use disclosure::Disclosure;
Expand Down

0 comments on commit e0f4558

Please sign in to comment.