Skip to content

Commit

Permalink
chore: Add docs to API
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan committed Nov 23, 2024
1 parent 8c9eee6 commit 3d117f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion atrium-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pub enum Error {
NotAllowed,
}

/// Type alias to use this library's [`Error`] type in a [`Result`](core::result::Result).
/// Type alias to use this library's [`Error`](enum@crate::error::Error) type in a [`Result`](core::result::Result).
pub type Result<T> = core::result::Result<T, Error>;
21 changes: 21 additions & 0 deletions atrium-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ pub struct UnknownData {
/// Corresponds to [the `unknown` field type].
///
/// [the `unknown` field type]: https://atproto.com/specs/lexicon#unknown
///
/// By using the [`TryFromUnknown`] trait, it is possible to convert to any type
/// that implements [`DeserializeOwned`](serde::de::DeserializeOwned).
///
/// ```
/// use atrium_api::types::{TryFromUnknown, Unknown};
///
/// #[derive(Debug, serde::Deserialize)]
/// struct Foo {
/// bar: i32,
/// }
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let value: Unknown = serde_json::from_str(r#"{"bar": 42}"#)?;
/// println!("{value:?}"); // Object({"bar": DataModel(42)})
///
/// let foo = Foo::try_from_unknown(value)?;
/// println!("{foo:?}"); // Foo { bar: 42 }
/// # Ok(())
/// # }
/// ```
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum Unknown {
Expand Down

0 comments on commit 3d117f3

Please sign in to comment.