Skip to content

Commit

Permalink
docs(cw-storey): API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Apr 30, 2024
1 parent cffe173 commit a090eef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/cw-storey/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use storey::storage::{StorageBackend, StorageBackendMut};

/// A wrapper around a type implementing [`cosmwasm_std::Storage`] that integrates it with [`storey`].
pub struct CwStorage<S>(pub S);

impl<S> StorageBackend for CwStorage<S>
Expand Down
13 changes: 13 additions & 0 deletions crates/cw-storey/src/containers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
//! Storage containers for use with [*CosmWasm*] smart contracts.
//!
//! [*CosmWasm*]: https://github.com/CosmWasm/cosmwasm
/// The [`storey::containers::Item`] type with the default encoding for [*CosmWasm*] smart
/// contracts.
///
/// [*CosmWasm*]: https://github.com/CosmWasm/cosmwasm
pub type Item<T> = storey::containers::Item<T, crate::encoding::CwEncoding>;

/// The [`storey::containers::Column`] type with the default encoding for [*CosmWasm*] smart
/// contracts.
///
/// [*CosmWasm*]: https://github.com/CosmWasm/cosmwasm
pub type Column<T> = storey::containers::Column<T, crate::encoding::CwEncoding>;

pub use storey::containers::Map;
9 changes: 9 additions & 0 deletions crates/cw-storey/src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use storey::encoding::{Cover, DecodableWithImpl, EncodableWithImpl, Encoding};

/// A simple encoding that uses [*MessagePack*] to encode and decode data.
///
/// This type implements the [`Encoding`] trait (see [`storey::encoding`]), which means it can
/// be used with some of [`storey`]'s containers to encode and decode values.
///
/// You're unlikely to need to use this type directly for basic library usage. You might
/// need it if you're trying to use third-party containers this crate does not provide.
///
/// [*MessagePack*]: https://msgpack.org/
pub struct CwEncoding;

impl Encoding for CwEncoding {
Expand Down
13 changes: 13 additions & 0 deletions crates/cw-storey/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
//! An integration of [`storey`] with [*CosmWasm*].
//!
//! This crate provides
//! - a [*CosmWasm*] storage backend for use with [`storey`] collections,
//! - a [*MessagePack*] encoding integration to be used for serializing and deserializing
//! values, and
//! - a set of container re-exports that remove the need to manually specify the
//! encoding, instead relying on the default [*MessagePack*] encoding.
//!
//! [*CosmWasm*]: https://github.com/CosmWasm/cosmwasm
//! [*MessagePack*]: https://msgpack.org/
mod backend;
pub mod containers;
mod encoding;

pub use backend::CwStorage;
pub use encoding::CwEncoding;
3 changes: 3 additions & 0 deletions crates/storey-encoding/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub trait Encoding {
/// The error type returned when encoding fails.
type EncodeError;

/// The error type returned when decoding fails.
type DecodeError;
}

Expand Down

0 comments on commit a090eef

Please sign in to comment.