forked from alemi/upub
feat(apb): helper: Option<String> to Field<&str>
This commit is contained in:
parent
456ca2d8b1
commit
ab006ffde9
2 changed files with 21 additions and 6 deletions
18
apb/src/field.rs
Normal file
18
apb/src/field.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("missing field '{0}'")]
|
||||
pub struct FieldErr(pub &'static str);
|
||||
|
||||
pub type Field<T> = Result<T, FieldErr>;
|
||||
|
||||
|
||||
// TODO this trait is really ad-hoc and has awful naming...
|
||||
|
||||
pub trait OptionalString {
|
||||
fn str(self) -> Option<String>;
|
||||
}
|
||||
|
||||
impl OptionalString for Field<&str> {
|
||||
fn str(self) -> Option<String> {
|
||||
self.ok().map(|x| x.to_string())
|
||||
}
|
||||
}
|
|
@ -98,6 +98,9 @@ pub mod target;
|
|||
mod key;
|
||||
pub use key::{PublicKey, PublicKeyMut};
|
||||
|
||||
pub mod field;
|
||||
pub use field::{Field, FieldErr};
|
||||
|
||||
#[cfg(feature = "jsonld")]
|
||||
mod jsonld;
|
||||
|
||||
|
@ -131,12 +134,6 @@ pub use types::{
|
|||
},
|
||||
};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("missing field '{0}'")]
|
||||
pub struct FieldErr(pub &'static str);
|
||||
|
||||
pub type Field<T> = Result<T, FieldErr>;
|
||||
|
||||
#[cfg(feature = "unstructured")]
|
||||
pub fn new() -> serde_json::Value {
|
||||
serde_json::Value::Object(serde_json::Map::default())
|
||||
|
|
Loading…
Reference in a new issue