Skip to content

Commit 3d117f3

Browse files
committed
chore: Add docs to API
1 parent 8c9eee6 commit 3d117f3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: atrium-api/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ pub enum Error {
1010
NotAllowed,
1111
}
1212

13-
/// Type alias to use this library's [`Error`] type in a [`Result`](core::result::Result).
13+
/// Type alias to use this library's [`Error`](enum@crate::error::Error) type in a [`Result`](core::result::Result).
1414
pub type Result<T> = core::result::Result<T, Error>;

Diff for: atrium-api/src/types.rs

+21
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ pub struct UnknownData {
144144
/// Corresponds to [the `unknown` field type].
145145
///
146146
/// [the `unknown` field type]: https://atproto.com/specs/lexicon#unknown
147+
///
148+
/// By using the [`TryFromUnknown`] trait, it is possible to convert to any type
149+
/// that implements [`DeserializeOwned`](serde::de::DeserializeOwned).
150+
///
151+
/// ```
152+
/// use atrium_api::types::{TryFromUnknown, Unknown};
153+
///
154+
/// #[derive(Debug, serde::Deserialize)]
155+
/// struct Foo {
156+
/// bar: i32,
157+
/// }
158+
///
159+
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
160+
/// let value: Unknown = serde_json::from_str(r#"{"bar": 42}"#)?;
161+
/// println!("{value:?}"); // Object({"bar": DataModel(42)})
162+
///
163+
/// let foo = Foo::try_from_unknown(value)?;
164+
/// println!("{foo:?}"); // Foo { bar: 42 }
165+
/// # Ok(())
166+
/// # }
167+
/// ```
147168
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
148169
#[serde(untagged)]
149170
pub enum Unknown {

0 commit comments

Comments
 (0)