diff --git a/apb/src/field.rs b/apb/src/field.rs new file mode 100644 index 0000000..336148e --- /dev/null +++ b/apb/src/field.rs @@ -0,0 +1,18 @@ +#[derive(Debug, thiserror::Error)] +#[error("missing field '{0}'")] +pub struct FieldErr(pub &'static str); + +pub type Field = Result; + + +// TODO this trait is really ad-hoc and has awful naming... + +pub trait OptionalString { + fn str(self) -> Option; +} + +impl OptionalString for Field<&str> { + fn str(self) -> Option { + self.ok().map(|x| x.to_string()) + } +} diff --git a/apb/src/lib.rs b/apb/src/lib.rs index bf0feb4..691b983 100644 --- a/apb/src/lib.rs +++ b/apb/src/lib.rs @@ -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 = Result; - #[cfg(feature = "unstructured")] pub fn new() -> serde_json::Value { serde_json::Value::Object(serde_json::Map::default())